开发者

Add a view to a UITableViewCell's contentView when it is selected

I am trying to add a new view with 5 buttons to a cell once it is selected. I am trying to do this in 3 different ways.开发者_如何学JAVA The first one is by checking if it is selected inside the

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

method.

if (cell == nil ) {
//initial customizaton of cells
} else {
   if ([cell isSelected]) {
   //I would add the view to the cell's contentView here but it never enters this if even though the cell is still blue, I scrolled the table back and forth several times and the blue cell never evaluated here

   }
}

I have also tried to do it inside the following two methods:

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath

And:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

I used tableView:cellForRowAtIndexPath: to get a reference to the cell and when I had that reference I tried adding the view inside the cell's contentView but it didn't seem to work(by "didn't work" I mean it didn't appear, I'll debug this further).

I know I didn't provide much detailed code but that's because I mainly want to know what's the general principle of how it should be done. I want to know why the cell doesn't stay with the selected property equal to YES even though it stays blue (when selectionStyle is the default one) when I tap it. I want it to stay "blue"(selected) with that view inside it until I deselect it and remove said view.


Did you try creating your own custom UITableViewCell? I think that is the point, you can overload setSelected: method there.


I followed NR4TR's advice and so far so good. I have subclassed UITableViewCell and have overridden the setSelected method in it.

Hoping this is useful to someone else in the future!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜