我有一个 UIPickerView,在单独的视图 settingsViewController 中有很多行。选择一行后,将数据通过NSUSERDEFAULTS传递给我的MainViewController。但是,如果我返回 settingsViewController 并且不更改行,按下保存按钮 - pickerView 似乎发送值“nil”?
这是 UIPickerView 的代码和传递行的代码。
//PickerViewCode
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[picker selectRow:[defaults integerForKey:@"pickerRow"] inComponent:0 animated:YES];
}
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:
(NSInteger)component {
{
if ([skolor count] == 0)
return 1;
return [skolor count];
}}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row
forComponent:(NSInteger)component {
return [skolor objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setInteger:row forKey:@"pickerRow"];
//Passing pickerViewValue
- (IBAction)selectedRow:(id)sender {
SchoolSoftViewController2 *vc1 = [self.storyboard
instantiateViewControllerWithIdentifier:@"webview1"];
NSString *urlString = [valdSkola absoluteString];
[[NSUserDefaults standardUserDefaults] setObject:urlString forKey:@"UserURL"];
[self presentViewController:vc1 animated:YES completion:nil];
}