2012-09-26 17 views

回答

2

您可以從touch事件中獲取indexPath。修改您的buttonTapped方法是這樣的:

- (void) buttonTapped:(id) sender forEvent:(UIEvent *)event 

,然後使用類似以下內容:

NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:[[[event touchesForView:sender] anyObject] locationInView:tableView]]; 
0

如果只有一個部分,你也許可以使用UIViewtag財產。

類似以下的東西理論上會起作用。

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)idxPath 
{ 
    Your_UITableViewCell_Subclass * cell = [tableView dequeueCellWithIdentifier:@"..."]; 
    cell.button.tag = idxPath.row; 

    .... 

    return cell; 
} 

.... 

- (void) buttonTapped:(id) sender 
{ 
    int idx = ((UIButton *)sender).tag; 
    NSIndexPath * idxPath = [NSIndexPath indexPathForRow:idx inSection:0]; 
    UITableViewCell * cell = [self tableView:tableView cellForRowAtIndexPath:idxPath]; 

    // Do whatever you want to do with the cell 
} 
+0

此解決方案將無法處理多個節。 – danielbeard

相關問題