How to Sync selected row of UIPicker with previously entered data

一个人想着一个人 提交于 2019-12-06 15:50:14
Aaronium112

I figured it out. I iterated through the dataSource array for the picker to find the matching string then used selectRow:inComponent:animated on the picker to sync it up. Here's the code. I was triggering it in a textField delegate method.

- (void)textFieldDidBeginEditing:(UITextField *)textField{
    UIBarButtonItem *saveButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(save)];
    self.navigationItem.rightBarButtonItem = saveButtonItem;
    [saveButtonItem release];

    //Sync The Picker
    for(NSInteger i = 0; i < [pickerData count]; i++){
        NSString *string = [pickerData objectAtIndex:i];
        if([string isEqualToString:profileField.text]){
            pickerRow = i;
            break;  //Once we have it break out of the loop
        }
    }
    [myPicker selectRow:pickerRow inComponent:0 animated:NO];
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!