我试图消除的关于 PickerView 的一个烦人的事情是,如果用户必须从第零行移开并重新选择它。我希望这样,如果用户决定选择零行,他只需按下按钮即可转到下一个视图,并且将选择零行值。
有任何想法吗?
非常感谢
这是我的代码 - 目前,如果按下连接到 saveSelectedCondition 的按钮,并且 pickerView 没有移出第 0 行,则为 selectedCondition 返回 null,而不是第 0 行的条件值:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
Condition *condition = [[self.fetchedResultsController fetchedObjects] objectAtIndex:row];
self.selectedCondition = condition;
NSLog(@"The '%@' condition was selected using the picker", self.selectedCondition.name);
}
- (IBAction)saveSelectedCondition:(id)sender {
[self.selectedCondition setValue:@"YES" forKey:@"isSelectedCondition"];
[self.managedObjectContext save:nil];
NSLog(@"Saving selected condition (%@) with isSelectedCondition set to '%@'", self.selectedCondition.name, self.selectedCondition.isSelectedCondition);
}