在我的自定义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。
ExploreTableViewCell.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”,因此可能没有调用发布通知的方法。
另外,请注意细胞重复使用,请注意是否应该在此时移除观察者。