Add button to UITableViewCell's Accessory View

前端 未结 10 1930
没有蜡笔的小新
没有蜡笔的小新 2021-01-01 16:41

Goal: when a user selects a cell, a button is added to that cell. Within my didSelectRowAtIndexPath function I have the following:

UIButton *downloadButton =         


        
10条回答
  •  [愿得一人]
    2021-01-01 17:28

    Try this block of code instead of the block you provided above:

    UIButton *downloadButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [downloadButton setTitle:@"Download" forState:UIControlStateNormal];
    [downloadButton setFrame:CGRectMake(0, 0, 100, 35)];
    [tableView cellForRowAtIndexPath:indexPath].accessoryView = downloadButton;
    

    This should display the button, but you will still need to hook up some kind of selector to it using addTarget. (I am not sure if listening in for the accessoryButtonTappedForRowWithIndexPath delegate will work in this case, try that first and see if it fires on your button press.)

提交回复
热议问题