【发布时间】:2011-11-19 16:20:54
【问题描述】:
在我的通用应用程序中,我在 UIScrollView 中有一个 UIControl 视图。
按下设置按钮时,我添加另一个视图作为子视图,如下所示:
SetupController *setupview = [[SetupController alloc] initWithNibName:@"SetupView-iPad" bundle:nil];
[mainview addSubview:setupview.view];
子视图按预期显示。 在这个子视图中,我有一些按钮,允许用户在设置之间切换。 执行的操作保存在本地数据库中。
问题是:在 SubView 中的 ButtonClick 上,我必须刷新主视图才能应用更改。我已经测试了很多方法来实现这一点:
在子视图类中:
[self.parentViewController.view setNeedsDisplay];
没有结果。
然后我尝试通过通知刷新主视图:
我将此添加到我的子视图类文件中,在更改我的设置的函数中。
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:@"setEmoticon_NOTIFICATION" object:self];
}
然后我在 ViewDidLoad 方法中将观察者添加到我的主视图中:
[[NSNotificationCenter defaultCenter] addObserver:self 选择器:@selector(refreshView) name:@"setEmoticon_NOTIFICATION" object:nil];
并为此观察者创建函数:
-(void)refreshView{
NSLog(@"Notification!");
[self.view performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:YES];
}
在日志中我收到“通知!”关于更改设置。但无论我尝试什么,都没有刷新。 我尝试了 setNeedsDisplay, resignFirstResponder, [self viewDidLoad:] ,但仍然没有任何效果。
任何想法如何刷新我的主视图?
【问题讨论】:
-
你的主视图是什么视图?
标签: cocoa-touch ipad uikit notifications refresh