Objective c iAction始终返回iOS7中已单击索引的0
下面是我所拥有的Objective c iAction始终返回iOS7中已单击索引的0,objective-c,uitableview,row,nsindexpath,Objective C,Uitableview,Row,Nsindexpath,下面是我所拥有的 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"MainCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentif
- (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;
}
在IB中,我已设置此按钮的操作
- (IBAction)clickedCellAction:(id)sender {
UITableViewCell *clickedCell = (UITableViewCell *)[[sender superview] superview];
NSIndexPath *clickedButtonPath = [mainTableView indexPathForCell:clickedCell];
NSLog(@"row==%d", clickedButtonPath.row);
}
现在,当我运行它时,我总是在iOS 7中得到row==0
但是,它在iOS6中给出了正确的row==行
你知道为什么会这样吗?下面是我用过的
CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:mainTableView];
NSIndexPath *indexPath = [mainTableView indexPathForRowAtPoint:buttonPosition];
NSLog(@"row index---%d", indexPath.row);