我这样做是为了改变按钮的状态。这是一个书签样式的按钮。如果用户想要为详细视图添加书签,他单击星号。我想在根视图中取回信息。
这是我的 detailview.m 代码
- (IBAction)saveRow
{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *save = cellNumber;
if ([buttonSave.titleLabel.text isEqualToString:@"Sync off"]) {
[prefs setValue:@"YES" forKey:save];
[buttonSave setTitle:@"Sync on" forState:UIControlStateNormal];
[buttonSave setBackgroundImage:[UIImage imageNamed:@"clicked.png"] forState:UIControlStateNormal];
}
else {
[prefs setValue:@"NO" forKey:save];
[buttonSave setTitle:@"Sync off" forState:UIControlStateNormal];
[buttonSave setBackgroundImage:[UIImage imageNamed:@"notclicked.gif"] forState:UIControlStateNormal];
}
// save
[prefs synchronize];
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
if ([[NSUserDefaults standardUserDefaults] boolForKey:cellNumber])
{
[buttonSave setTitle:@"Sync on" forState:UIControlStateNormal];
[buttonSave setBackgroundImage:[UIImage imageNamed:@"clicked.png"] forState:UIControlStateNormal];
}
else {
[buttonSave setTitle:@"Sync off" forState:UIControlStateNormal];
[buttonSave setBackgroundImage:[UIImage imageNamed:@"notclicked.gif"] forState:UIControlStateNormal];
}
但是在根视图中,我不知道该怎么做才能做同样的事情。根视图是一个表视图。
有任何想法吗?