Problem in inserting segmented control to header view

后端 未结 2 1082
庸人自扰
庸人自扰 2021-01-21 15:50

I\'m trying to add a UISegmentedControl in my tableview. I have two sections in my tableview and I want the segmented control to be placed in the 2nd section. In my implementati

2条回答
  •  长发绾君心
    2021-01-21 16:30

    This is a late reaction, but I ran into the same issue and figured out the problem. In the code above, the headerView is recreated everytime the tableView calls reloadData (which in my occurs after I resort the data based on a click on the segmentedControl), and therefore the segmented control goes back to its original state, and touches are not apparently reflected.

    To solve this, I made segmentedControl an ivar, and check if it already exists. If so, then just call

    [headerView addSubview: segmentedControl];
    

    otherwise do the whole setup of the control.

    Hope this helps.

提交回复
热议问题