I have a custom TableCell and a UiButton is associated with this via IB. But the button action method always return the button index as zero
Below is my code
//Inside CellForRow
[cell.M_CtrlBtnChat addTarget: self
action: @selector(buttonPressed:withEvent:)
forControlEvents: UIControlEventTouchUpInside];
- (void) buttonPressed: (id) sender withEvent: (UIEvent *) event
{
UITouch * touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView: self.tableView];
NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint: location];
NSLog(@"%d", indexPath.row);
}
Here index path always return zero. Any idea . Please help me
[cell.M_CtrlBtnChat addTarget: self
action: @selector(buttonPressed:withEvent:)
forControlEvents: UIControlEventTouchUpInside];
cell.M_CtrlBtnChat.tag = indexPath.row;
- (void) buttonPressed: (id) sender withEvent: (UIEvent *) event
{
UIButton *btn = (UIButton *)sender;
NSLog(@"btn.tag %d",btn.tag);
UITouch * touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView: self.tableView];
NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint: location];
NSLog(@"%d", indexPath.row);
}
try this it may help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With