在我的自定义 UITableViewCell 中,我在 NSNotificationCenter 中添加了一个观察者:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopActivityIndicator) name:@"stopActivityIndicator" object:nil];
我在 UIViewController 中发布通知:
[[NSNotificationCenter defaultCenter] postNotificationName:@"stopActivityIndicator" object:nil];
这个函数“stopActivityIndicator”没有被调用,知道是什么原因导致的吗?
编辑:
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/