2009-12-07 40 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 
    } 
} 
相关问题