2009-12-07 47 views
0
  • (的UITableViewCell *)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath {確定Tableview中每一行的按鈕選擇?

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    btn.frame = CGRectMake(230.0f, 4.0f, 60.0f, 36.0f); 
    [btn setTitle:@"OK" forState:UIControlStateNormal]; 
    [btn setTitle:@"OK" forState:UIControlStateSelected]; 
    [btn addTarget:self action:@selector(onClickRename:) forControlEvents:UIControlEventTouchUpInside]; 
    [cell addSubview:btn]; 
    
    return cell; 
    

    }

但如果用戶選擇特定行的鍵,我可以通過onClickRename更改該圖片...但是,我可以通過哪些圖片的排列已經被觸及了

  • (void)tableView :(UITableView )tableView didSelectRowAtIndexPath :(NSIndexPath)indexPath?

回答

2

你可以做類似

[btn setTag:[indexPath] row] 

在你的設置,然後

- (void) onClickRename:(id)sender { 
    int row = sender.tag; 
} 

你知道哪些錶行被擊中。

0

蘋果採用以下技術,其Accessory示例代碼:

- (void)checkButtonTapped:(id)sender event:(id)event 
{ 
    NSSet *touches = [event allTouches]; 
    UITouch *touch = [touches anyObject]; 
    CGPoint currentTouchPosition = [touch locationInView:self.tableView]; 
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition]; 
    if (indexPath != nil) 
    { 
     // do what you want with the item at indexPath 
    } 
} 
相關問題