从特定行获取Picker数据

时间:2015-04-20 12:26:14

标签: ios uitableview uipickerview

当点击该单元格中的按钮时,我需要从每个单元格中获取拾取器值。如果我单击黑天鹅单元格中的贪睡按钮,我应该获得该单元格中的拾取器值。我从

获取行详细信息
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
    int section = indexPath.section;

int row = indexPath.row;
NSLog(@"section: %d / row: %d", section, row); 

感谢任何帮助。所有细胞都是定制细胞。

Screen shot

2 个答案:

答案 0 :(得分:0)

您可以从didSelectRowAtIndexPath中的每个单元格中的标签选择标记到选择器中获取值

pickerView.tag=indexPath.row;

然后在选择器委托中你可以执行类似下面的操作

 if (pickerView.tag == 1){
//do stuff
}else (pickerView.tag == 2){
//do other stuff
}

如果你想在这里使用,你甚至可以使用Switch。

答案 1 :(得分:0)

setTag UIButtons indexpath.rowUIPickerView//You can set it in `cellForRowAtIndexPath` method [yourSnoozbuton addTarget:self action:@selector(selectPickerTime:) forControlEvents:UIControlEventTouchDown]; ,如果它已经多部分,那么您可以按照此设置逻辑,设置-(IBAction)selectPickerTime:(UIButton *)sender { NSIndexPath *nowIndex = [NSIndexPath indexPathForRow:sender.tag inSection:0]; UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:nowIndex]; UIPickerView *pickerview = [cell viewWithTag:999999]; NSString *str = [timeArray objectAtIndex:[pickerview selectedRowInComponent:0]]; //if multi sectioned, get button as per logic. } 静态标签,永远不应该等于按钮标签,例如999999 Tag for Pickerview。

你可以通过addTarget设置target:action:forControlEvent方法来调用UIButton的实例方法,

{{1}}

在Instance方法中,您可以获得类似的选择器值

{{1}}
相关问题