简体   繁体   English

带有UIPicker选项的UITableView行选择

[英]UITableView Rows selection with UIPicker Option

I have a tableview with 5 rows, when I select a row it opens a UIPickerView in the next page to select options,the same things happen with 5 rows.Now I want ,The Pickervalue, It should be reflected on particular Row(right side) whichever I selected 我有一个包含5行的tableview ,当我选择一行时,它会在下一页打开一个UIPickerView来选择选项,同样的事情发生在5行上。 )无论我选择了哪个

and I have a button on the same page to perform on the selected rows values(UIPicker values).How to give options in Button.to select the Rows values which is been taken from UIPicker 我在同一页面上有一个按钮来对选定的行值(UIPicker值)执行。如何在Button.to中给出选项以选择从UIPicker获取的行数

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if(indexPath.row==0){

        Picker1 *logInController = [[Picker1 alloc] init];

    [[self navigationController] pushViewController:logInController animated:YES];
    }

    if(indexPath.row==1){

        Picker2 *logInController = [[Picker2 alloc] init];

        [[self navigationController] pushViewController:logInController animated:YES];
    }
}

like above I have opened the UIPIcker and select the options. 像上面一样,我已经打开了UIPIcker并选择了选项。

IN PICKER1.m 在PICKER1.m

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

    // update label text to show selected option

    NSString* string=[NSString stringWithFormat:@"you are selected %@",[list objectAtIndex:row]];

    label.text=string;

}



- (void)viewDidLoad

{      
    [super viewDidLoad];

    list =[[NSMutableArray alloc]init];
    [list addObject:@"GPS"];
    [list addObject:@"NONE"];


}
  1. You need to modify datasource of tableView. 您需要修改tableView的数据源。 You can take array of dictionaries(with keys leftTitle & rightTitle). 您可以使用字典数组(具有leftTitle和rightTitle键)。
  2. You need to implement protocol in Picker1 & Picker2 with delegate method valueSelected: 您需要使用委托方法valueSelected在Picker1&Picker2中实现协议:
  3. Implement delegate in your controller with tableView. 使用tableView在您的控制器中实现委托。
  4. You need to save globally index of selected row. 您需要保存所选行的全局索引。 Set delegate to self while pushing pickers. 在推动选择器时将委托设置为自我。
  5. When you tap on button in picker controller call valueSelected: delegate & pass value selected in picker. 当您在选择器控制器中点击按钮时,调用值已选定:在选择器中选择的委托和传递值。
  6. In Your controller with tableView where you have implemented protocol methods, get value and save in datasource(as value for key "rightTitle" in dictionary with selected index). 在已实现协议方法的带有tableView的控制器中,获取值并保存在数据源中(作为具有选定索引的字典中键“ rightTitle”的值)。
  7. Reload table. 重新加载表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM