Search code examples
iosobjective-ckey-value-observingcustom-cellkvc

Observing custom cell


I am trying to add observer (KVO) to observe my custom cell. Once the cell is selected I should receive a notification of the event. My code:

[colMain addObserver:self forKeyPath:@"colMain" options:0 context:NULL];

}

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{

    if (keyPath == @"colMain") {
        NSLog(@"cell Selected");
        [self performSelector:@selector(deleteCell) withObject:nil];

    }
}

colMain stands for collectionView. I am not quite sure how to do it cause I don't have customCell as a property otherwise it does not compile. Any ideas?


Solution

  • Why not just set a delegate on your collection view and then implement one of these two methods?

    [– collectionView:shouldSelectItemAtIndexPath:]

    [– collectionView:didSelectItemAtIndexPath:]