سؤال

Below is what I have.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"MainCell";

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

    UIButton *myButton = (UIButton *)[cell viewWithTag:999999];
    // setting image to button...
    return cell;    
}

In IB, I have set action to this button...

- (IBAction)clickedCellAction:(id)sender {

    UITableViewCell *clickedCell = (UITableViewCell *)[[sender superview] superview];
    NSIndexPath *clickedButtonPath = [mainTableView indexPathForCell:clickedCell];

    NSLog(@"row==%d", clickedButtonPath.row);
}

Now when I run this, I always get row==0 in iOS 7.

However it gives proper row== in iOS6.

Any idea why this is happening?

هل كانت مفيدة؟

المحلول

Below is what I used...

CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:mainTableView];
NSIndexPath *indexPath = [mainTableView indexPathForRowAtPoint:buttonPosition];
NSLog(@"row index---%d", indexPath.row);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top