別のビューであるsettingsViewControllerに多くの行を持つUIPickerViewがあります。行が選択されると、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];
}