我在带有完成和取消按钮的 uipopover 中有一个完美工作的 uipickerview。当用户多次打开 uipickerview 时,我可以保存最后选择的行并将其显示为默认值。问题是,当用户注销并登录时,我希望 uipickerview 重新启动,即,当我打开 uipickerview 并单击完成按钮(不选择任何行)时,我希望它使用默认行,即。row0 但它在注销前显示最后选择的行!我该如何解决这个问题?非常感谢帮助。
NSString *selectedType = @"ALL";
int rowselected = 0;
- (void)viewDidLoad
{
[super viewDidLoad];
rowselected = 0;
_typearray = [[NSArray alloc] initWithObjects:@"ALL", @"COACH", @"GROUP", @"PRIVATE", nil];
NSInteger lastrow =[[[NSUserDefaults standardUserDefaults] objectForKey:@"gueststyperow"] integerValue];
if(lastrow!=0)
[self.picktype selectRow:lastrow inComponent:0 animated:NO];
else
[self.picktype selectRow:0 inComponent:0 animated:NO];
}
//按下完成按钮:
- (IBAction)doneButtonPress:(UIBarButtonItem *)sender {
NSLog(@"%@",_delegate);
NSNumber *temprow = [NSNumber numberWithInt:rowselected];
[[NSUserDefaults standardUserDefaults] setValue:temprow forKey:@"gueststyperow"];
[_delegate sendtype:selectedType];
}
//PICKER视图选择
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component{
rowselected = row;
selectedType = [_typearray objectAtIndex:row];
}