在UITableView中檢測哪個(gè)UIButton被按下我有一個(gè)UITableView有5個(gè)UITableViewCells..每個(gè)單元格包含一個(gè)UIButton其設(shè)置如下:- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *identifier = @"identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
[cell autorelelase];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 5, 40, 20)];
[button addTarget:self action:@selector(buttonPressedAction:) forControlEvents:UIControlEventTouchUpInside];
[button setTag:1];
[cell.contentView addSubview:button];
[button release];
}
UIButton *button = (UIButton *)[cell viewWithTag:1];
[button setTitle:@"Edit" forState:UIControlStateNormal];
return cell;}我的問題是:在buttonPressedAction:方法,如何知道已按哪個(gè)按鈕。我考慮過使用標(biāo)簽,但我不確定這是最好的路線。我希望能以某種方式標(biāo)記indexPath進(jìn)入控制室。- (void)buttonPressedAction:(id)sender{
UIButton *button = (UIButton *)sender;
// how do I know which button sent this message?
// processing button press for this row requires an indexPath. }這樣做的標(biāo)準(zhǔn)方法是什么?
在UITableView中檢測哪個(gè)UIButton被按下
繁華開滿天機(jī)
2019-06-14 16:18:26