How to get UITableviewCell index by UIButton Click in iOS app?

Hi Friends,
Today am going to post to get current UITableviewCell indexPath by UIButton Action.

– (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
static NSString *CellIdentifier = @”Cell”;

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;

UIButton *getInfoButton = [UIButton buttonWithType:UIButtonTypeCustom];
getInfoButton.titleLabel.textAlignment = UITextAlignmentRight;
getInfoButton.titleLabel.font = [UIFont systemFontOfSize:13];
[getInfoButton addTarget:self action:@selector(getUserInfo:) forControlEvents:UIControlEventTouchUpInside];
getInfoButton.tag = 100;
[cell.contentView addSubview: getInfoButton];
}
else
{
UIButton * getInfoButton = (UIButton *) [cell.contentView viewWithTag:105];
}
return cell;
}

-(void)getUserInfo:(id) sender
{
UITableViewCell *clickedCell = (UITableViewCell *)[[sender superview] superview];
NSIndexPath *clickedButtonIndexPath = [messagesTableView indexPathForCell:clickedCell];

int selectedIndexPath = clickedButtonIndexPath.row;
NSLog(@”SelectedIndexPath: %d”, selectedIndexPath);

NSString *userInfo = [userInformationArray objectAtIndex:selectedIndexPath];
NSLog(@”userInfo : %@”, userInfo);
}

I hope it will help anyone. Happy coding. Thanks.

Warm Regards,
Yuvaraj.M