ios - UITableviewCell 中的观察者

标签 ios uitableview nsnotificationcenter

在我的自定义 UITableViewCell 中,我在 NSNotificationCenter 中添加了一个观察者:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopActivityIndicator) name:@"stopActivityIndicator" object:nil];

我在 UIViewController 中发布通知:

[[NSNotificationCenter defaultCenter] postNotificationName:@"stopActivityIndicator" object:nil];

这个函数“stopActivityIndi​​cator”没有被调用,知道是什么原因导致的吗?

编辑:

ExploreViewController.m

-(void)showCorrectBannerAfterPlusButtonClicked:(NSNotification *)notification
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"stopActivityIndicator" object:nil];
}

ExploreViewController 包含一个带有 ExploreTableViewCells 的 UITableView。

探索TableViewCell.m

- (IBAction)plusButtonClicked:(id)sender
{
    self.plusButton.hidden = YES;
    [self.plusButtonActivityIndicator startAnimating];


    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(stopActivityIndicator) name:@"stopActivityIndicator" object:nil];

}

-(void)stopActivityIndicator
{
    _plusButton.hidden = NO;
    [self.plusButtonActivityIndicator stopAnimating];

    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"stopActivityIndicator" object:nil];
}

最佳答案

好的,问题来了,你什么时候调用“showCorrectBannerAfterPlusButtonClicked”?因为这是您发布 tableViewCell 观察到的通知的方法。

我看到的是通知观察者添加和删除,但我没有看到 UIViewController 如何知道何时调用单元格的“plusButtonClicked”,因此也许没有调用发布通知的方法。

此外,请小心单元格的重复使用,请记住是否应该在此时删除观察者。

关于ios - UITableviewCell 中的观察者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54764317/

相关文章:

iphone - 在 uinavigationcontroller 中推送 safari 浏览器

iphone - 折叠 UITableView

ios - NSNotification 监听器 iOS

ios - NSNotificationCenter postNotificationName 在 swift 和 object-c 中崩溃,为什么?

ios - 在 UITableView 中访问多维数组值

ios - 如果我希望它在整个应用程序生命周期内都存在,是否需要手动删除观察者?

IOS UIMenuController UIMenuItem,如何确定使用通用选择器方法选择的项目

iphone - 在 map View 中实现获取方向

ios - initWithNibName 不实现父类(super class) - Swift

ios - UITableViewCell,显示没有滑动的滑动式删除按钮