如何重新加载 UIView?

发布于 2024-11-01 06:15:42 字数 1131 浏览 6 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谷夏 2024-11-08 06:15:42

其实我没想到会更新。 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 called reloadData that in turn sends the appropriate reload message to your OHGridView.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文