iPhone - 启动不同类别的选择器

发布于 2024-09-02 04:19:36 字数 1012 浏览 9 评论 0原文

我想重新加载一个表视图,该视图位于另一个名为“WriteIt_MobileAppDelegate”的类中,该类来自我的其他类(称为“Properties”)。我尝试通过 NSNotificationCenter 类来执行此操作 - 日志被调用但表从未更新。

Properties.h:

 [[NSNotificationCenter defaultCenter] postNotificationName:@"NameChanged"
              object:[WriteIt_MobileAppDelegate class]
               userInfo:nil]; 

WriteIt_MobileAppDelegate.m

-(void)awakeFromNib {

[[NSNotificationCenter defaultCenter] addObserver:self 选择器:@selector(reloadItProperties:) 名称:@“NameChanged”对象:self];

}

- (void) reloadItProperties: (NSNotification *)notification {

 NSLog(@"Reloading Data"); //this gets called
[[self navigationController] dismissModalViewControllerAnimated:YES];
[self.navigationController popToRootViewControllerAnimated:YES];
 [self.tblSimpleTable reloadData];
 [self.tblSimpleTable reloadSectionIndexTitles];
 // but the rest doesn't
}

我在这里做错了什么

I'd like to reload a table view which is in another class called "WriteIt_MobileAppDelegate" from one of my other classes which is called "Properties". I've tried to do this via the NSNotificationCenter class - the log gets called but the table is never updated.

Properties.h:

 [[NSNotificationCenter defaultCenter] postNotificationName:@"NameChanged"
              object:[WriteIt_MobileAppDelegate class]
               userInfo:nil]; 

WriteIt_MobileAppDelegate.m

-(void)awakeFromNib {

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reloadItProperties:)
name:@"NameChanged" object:self];

}

- (void) reloadItProperties: (NSNotification *)notification {

 NSLog(@"Reloading Data"); //this gets called
[[self navigationController] dismissModalViewControllerAnimated:YES];
[self.navigationController popToRootViewControllerAnimated:YES];
 [self.tblSimpleTable reloadData];
 [self.tblSimpleTable reloadSectionIndexTitles];
 // but the rest doesn't
}

What am I doing wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

污味仙女 2024-09-09 04:19:36

似乎您使用的 object 参数错误:

addObserver:selector:name:object:

通知发送者
该对象的
观察者想要的通知
接收;
也就是说,只有通知
该发件人发送的邮件将发送至
观察者。如果你通过了 nil,
通知中心不使用
通知的发送者决定
是否将其传递给观察者。

Seems like you are using the object parameter wrong:

addObserver:selector:name:object:

notificationSender
The object whose
notifications the observer wants to
receive;
that is, only notifications
sent by this sender are delivered to
the observer. If you pass nil, the
notification center doesn’t use a
notification’s sender to decide
whether to deliver it to the observer.

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