![](/img/trans.png)
[英]How to add uipicker view in ui tableview in did selected row method
[英]How to Sync selected row of UIPicker with previously entered data
我有一個Picker用作UITextField的inputView而不是鍵盤。 用戶撥入他們的選擇,保存然后關閉視圖。 當您回到該視圖並撥入新的選擇時,選擇器與保存的數據不同步。
選擇器正在使用字符串數組作為數據源。
因此,例如,查看下面的圖片,您可以看到選取器處於它的第一個空位置。 但是我想要的是讓選擇器撥入RE2或將其他任何一個選項保存在textField中。
如何同步兩者?
我想到了。 我遍歷dataSource數組以供選擇器查找匹配的字符串,然后在選擇器上使用selectRow:inComponent:animated將其同步。 這是代碼。 我在textField委托方法中觸發了它。
- (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];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.