任何想法?
非常感谢
这是我的代码 - 目前,如果按下连接到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);
}
答案 0 :(得分:0)
试试吧......
- (IBAction)saveSelectedCondition:(id)sender {
myText.text = [myArray objectAtIndex:0];//Just add this line for set first value
[self.selectedCondition setValue:@"YES" forKey:@"isSelectedCondition"];
[self.managedObjectContext save:nil];
NSLog(@"Saving selected condition (%@) with isSelectedCondition set to '%@'", self.selectedCondition.name, self.selectedCondition.isSelectedCondition);
}
Set first value when your picker view called.
答案 1 :(得分:0)
我现在使用以下代码在performFetch之后将其整理出来:
[self performFetch];
NSLog(@"The following Conditions were fetched for the Picker by SelectorViewController:");
for (Condition *fetchedCondition in [self.fetchedResultsController fetchedObjects]) {
if (fetchedCondition ==[[self.fetchedResultsController fetchedObjects] objectAtIndex:0])
{[fetchedCondition setValue:@"YES" forKey:@"isSelectedCondition"];
self.selectedCondition = fetchedCondition;}
else
[fetchedCondition setValue:@"NO" forKey:@"isSelectedCondition"];
[self.managedObjectContext save:nil];
NSLog(@"Condition: %@, isSelectedCondition %@", fetchedCondition.name, fetchedCondition.isSelectedCondition);
}
}