我正在使用Xcode 4.5并且定位iOS 5及更高版本。
我有一个弹出窗口,允许用户更改底层视图的背景。从popover刷新视图
当点击“按钮”时,它需要点击两次以查看更改。
我正在使用NSNotification
。我曾试过授权,但它什么也没做。
任何帮助或提示将不胜感激。
从viewWillAppear中:
// nav button is for background image selection
navigationBtn.tag = buttonTag;
[navigationBtn setBackgroundImage:[UIImage imageNamed:tempImage] forState:UIControlStateNormal];
if (selectFlag) {
[navigationBtn addTarget:self action:@selector(BGSelected:) forControlEvents:UIControlEventTouchUpInside];
} else {
navigationBtn.adjustsImageWhenHighlighted = NO;
}
而对于选择的方法:
- (void)BGSelected:(id)sender {
self.bgtag = [sender tag];
SettingsDAO *settingsDao = [[SettingsDAO alloc] init];
if ([self.currentView isEqualToString:@"New_Journal"])
{
NSLog(@"Update Journals Background");
[settingsDao updateJournalBackgroundId:self.journalId withBackgroundId:self.bgtag];
}
// notification to let EntryView know the background has changed
[[NSNotificationCenter defaultCenter] postNotificationName:@"aBackgroundChanged"
object:self];
[settingsDao release];
}
的NSNotification方法:
- (void)aBackgroundChanged:(NSNotification *)notification {
[self invalidate];
[self reloadSettings];
}
通知和委托是处理这个问题的正确方法。您必须确保popover调用者正在监听该通知。我建议做一个BackgroundChange一个NSString常量。或者,确保popover控制器中的委托不为零。 – Leonardo
我怎样才能使通知一个NSString常量,为什么这将是必要的?调用者正在监听...我在ViewDidLoad中有一个观察者。它应该在别的地方,因为视图是在popover被调用之前加载的? –
像这样做一个常量:NSString * const BackgroundChange = @“aBackgroundChange”;它会避免误拼,最重要的是Xcode可以为你自动完成。尝试在创建弹出窗口后立即设置监听器或将调用方分配为委托。 – Leonardo