如何重新加载 UIView?
我有一个 UINavigationController,用户可以在其中返回/第四个。当用户返回时,我希望重新加载 UIView。 (我实际上使用的是 OHGridView )。在我的 ViewWillDisappear
上,我做了这样的事情:
- (void)viewWillDisappear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] postNotificationName:@"ReloadOHGridView" object:self];
}
所以当他们返回时,它将向 OHGridView 发送 NSNotification 以刷新其数据。它被调用,但出现错误由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[DetailViewController reloadData]:无法识别的选择器发送到实例0x4b9e9f0
这是我如何设置我的NSNotificationCenter(在my DetailViewController):
- (void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ReloadGridNotification:) name:@"ReloadOHGridView" object:nil];
}
- (void)ReloadGridNotification:(NSNotification *)notification{
[database executeNonQuery:@"DELETE * FROM images"];
[items removeAllObjects];
[self reloadData];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
现在你会认为它会更新,但我收到了这个错误......请帮忙!
库尔顿
I have a UINavigationController where the user can go back/fourth. When the user goes back, I want that UIView to reload. ( I am actually using an OHGridView ). On my ViewWillDisappear
, I do something like this:
- (void)viewWillDisappear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] postNotificationName:@"ReloadOHGridView" object:self];
}
So when they go back, it will send a NSNotification to the OHGridView to refresh it's data. It get's called, but it get's an error Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DetailViewController reloadData]: unrecognized selector sent to instance 0x4b9e9f0
Here's how I set up my NSNotificationCenter (in my DetailViewController):
- (void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ReloadGridNotification:) name:@"ReloadOHGridView" object:nil];
}
- (void)ReloadGridNotification:(NSNotification *)notification{
[database executeNonQuery:@"DELETE * FROM images"];
[items removeAllObjects];
[self reloadData];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
Now you would think it would update, but I get that error... Please help!
Coulton
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
其实我没想到会更新。
reloadData
不是 UIViewController 的记录方法的名称,并且您似乎没有自己实现该方法。我不熟悉 OHGridView,但我可能这就是您想要向其发送 reloadData 消息的对象。因此,您可以将设置的观察者从
self
更改为 OHGridView 实例,或者您可以在视图控制器中实现一个名为reloadData
的方法,该方法依次发送适当的数据将消息重新加载到您的 OHGridView。Actually, I wouldn't think that it would update.
reloadData
isn't the name of a documented method of UIViewController, and you don't seem to have implemented one yourself. I'm not familiar with OHGridView, but I perhaps that's the object to which you want to send the reloadData message.So you can change the observer that you set up from
self
to your instance of OHGridView, or you can implement a method in your view controller calledreloadData
that in turn sends the appropriate reload message to your OHGridView.