Can anyone tell me how to call a custom function created for a UIButton
clicked inside a cell in a didSelectRowAtIndexPath. I have a shopping cart button in a tableViewCell, when clicked I am changing the icon and maintaining a shopping cart list which works fine. But what I am trying to achieve is when user clicks on any row this functionality of UIButton
can be used as well.
I have written a following Code in cellForRowAtIndexPath
cell.addToCardButton.tag = indexPath.row;
[cell.addToCardButton addTarget:self action:@selector(CartTapped:) forControlEvents:UIControlEventTouchUpInside];
//cartTapped function defination
- (void)CartTapped:(UIButton*)sender {
NSUInteger index = sender.tag;
Product *product = [results objectAtIndex:index];
NSIndexPath *ip = [NSIndexPath indexPathForRow:index inSection:0];
if(sender.selected) {
UIImage *btnImage = [UIImage imageNamed:@"AddCart.png"];
[sender setImage:btnImage forState:UIControlStateNormal];
[BasketObjects delete:product] ;
} else {
sender.imageView.image =[UIImage imageNamed:@"ClearCart.png"];
[[BasketObjects sharedInstance].basketObjects addObject:product];
}
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:ip] withRowAnimation:UITableViewRowAnimationMiddle];
}