Наблюдатель в UITableviewCell - PullRequest
       7

Наблюдатель в UITableviewCell

0 голосов
/ 19 февраля 2019

В своем пользовательском 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 содержит UITableView с ExploreTableViewCells.

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];
}

1 Ответ

0 голосов
/ 19 февраля 2019

Хорошо, вопрос, когда вы вызываете «showCorrectBannerAfterPlusButtonClicked» ??Поскольку это метод, в котором вы публикуете уведомление, наблюдаемое таблицей ViewCell.

То, что я вижу, это добавление и удаление наблюдателя уведомлений, но я не вижу, как UIViewController знает, когда вызывается ячейка «plusButtonClicked», поэтому, возможно, метод, отправляющий уведомление, не вызывается.

Кроме того, будьте осторожны с повторным использованием ячейки, имейте в виду, следует ли удалить наблюдателя в этой точке.

...