UITableviewCell中的观察者

问题描述 投票:0回答:1

在我的自定义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。

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];
}
ios uitableview nsnotificationcenter
1个回答
0
投票

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

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

另外,请注意细胞重复使用,请注意是否应该在此时移除观察者。

© www.soinside.com 2019 - 2024. All rights reserved.