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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在UITableView中檢測哪個UIButton被按下

在UITableView中檢測哪個UIButton被按下

iOS
繁華開滿天機 2019-06-14 16:18:26
在UITableView中檢測哪個UIButton被按下我有一個UITableView有5個UITableViewCells..每個單元格包含一個UIButton其設置如下:- (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:方法,如何知道已按哪個按鈕。我考慮過使用標簽,但我不確定這是最好的路線。我希望能以某種方式標記indexPath進入控制室。- (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. }這樣做的標準方法是什么?
查看完整描述

3 回答

?
大話西游666

TA貢獻1817條經驗 獲得超14個贊

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

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

然后,在接觸中檢索處理程序觸摸坐標,并從該坐標計算索引路徑:

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


查看完整回答
反對 回復 2019-06-14
?
HUWWW

TA貢獻1874條經驗 獲得超12個贊

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

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


查看完整回答
反對 回復 2019-06-14
  • 3 回答
  • 0 關注
  • 580 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號