第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

在UITableView中檢測哪個(gè)UIButton被按下

在UITableView中檢測哪個(gè)UIButton被按下

iOS
繁華開滿天機(jī) 2019-06-14 16:18:26
在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)方法是什么?
查看完整描述

3 回答

?
大話西游666

TA貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超14個(gè)贊

蘋果的附件示例使用以下方法:

[button addTarget:self action:@selector(checkButtonTapped:) forControlEvents:UIControlEventTouchUpInside];

然后,在接觸中檢索處理程序觸摸坐標(biāo),并從該坐標(biāo)計(jì)算索引路徑:

- (void)checkButtonTapped:(id)sender{
    CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];
    if (indexPath != nil)
    {
     ...
    }}


查看完整回答
反對(duì) 回復(fù) 2019-06-14
?
HUWWW

TA貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超12個(gè)贊

我就是這樣做的。簡明扼要:

- (IBAction)buttonTappedAction:(id)sender{
    CGPoint buttonPosition = [sender convertPoint:CGPointZero
                                           toView:self.tableView];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];
    ...}


查看完整回答
反對(duì) 回復(fù) 2019-06-14
  • 3 回答
  • 0 關(guān)注
  • 593 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)