How to make UITableView Header selectable?

后端 未结 12 1301
执笔经年
执笔经年 2020-12-16 11:49

I have made a custom section-header for UITableView, that includes some controls like segmented control, UIImageView ,etc. It successfully appears, but it\'s not tappable so

12条回答
  •  生来不讨喜
    2020-12-16 12:38

    You can simply add a UIButton to your header view (or your header view can be a UIButton itself).

    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
            static NSString *cellIdentifier = @"cellIdentifier";
    
        UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
        UIButton *cellButton = (UIButton*)[cell viewWithTag:1];
        [cellButton addTarget:self action:@selector(premiumSectionClicked:) forControlEvents:UIControlEventTouchUpInside];
    
        return cell;
    }
    
    -(void)buttonTapped:(id)sender{
    
    }
    

提交回复
热议问题