I found already some solution how to detect touch in my cell, but they are made for one section. I have more then 1(8 tbh). Following code are making touch for few cells instead of one. So question is, what the clear solution to my problem? Here the code:
- (CatalogItemTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CatalogItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
CatalogItemModel *currentItemModel;
if(isCatSelected) {
currentItemModel = [[self.itemsArray objectForKey:[[self.sectionArray objectAtIndex:selectedIndexPath] valueForKey:@"id"]] objectAtIndex:indexPath.row];
} else {
currentItemModel = [[self.itemsArray objectForKey:[[self.sectionArray objectAtIndex:indexPath.section] valueForKey:@"id"]] objectAtIndex:indexPath.row];
}
[cell setItemModel:currentItemModel];
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(didTapFav:)];
[cell.overFavorite addGestureRecognizer:gestureRecognizer]; //overFavorite is UIView to detect touch
return cell;
}
Action func:
-(void)didTapFav:(UITapGestureRecognizer*)recognizer {
NSString *token = [ProfileManager getToken];
if(token.length > 0){
[[NSNotificationCenter defaultCenter] postNotificationName:@"addToFavorite" object:self];
} else {
[self showErrorWithTitle:@"Auth" andText:@"To add item in Favorite!"];
}
}
Function inside CatalogItemTableViewCell:
-(void)addToFavorite {
if(isFavorite) {
[ApiManager tryAddToFavItem:[NSString stringWithFormat:@"%ld", (long)self.currentModel.uid] :^{
//Some API request
}];
}
}