Detecting which UIButton was pressed in a UITableView

前端 未结 26 2958
小蘑菇
小蘑菇 2020-11-22 00:40

I have a UITableView with 5 UITableViewCells. Each cell contains a UIButton which is set up as follows:

- (UITableView         


        
26条回答
  •  旧时难觅i
    2020-11-22 00:59

    It's simple; make a custom cell and take a outlet of button

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
        {
             NSString *identifier = @"identifier";
            customCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
        cell.yourButton.tag = indexPath.Row;
    
    - (void)buttonPressedAction:(id)sender
    

    change id in above method to (UIButton *)

    You can get the value that which button is being tapped by doing sender.tag.

提交回复
热议问题