开发者

iPhone didSelectRowAtIndexPath not firing

So I am trying to default to having the first row in a tableView selected when my view first loads. I am doing this my viewWillAppear method:

NSIndexPath *tempPath= [NSIndexPath indexPathForRow:0 inSection:0];

[the开发者_开发百科Table.delegate tableView:theTable didSelectRowAtIndexPath:tempPath];

Which fires the method, but the cell doesn't stay selected. This fires the proper method and executes the code in there, and I am never deselecting it. After the user presses another cell, it stays selected properly. Just not the first time. Does anyone know what may be causing this weirdness? I have even tried to do this:

[[theTable.delegate tableView:theTable cellForRowAtIndexPath:tempPath] setSelected:YES];

Thoughts?


First of all, you shouldn't be calling the delegate methods directly like that.

If you do need to select a cell programmatically (like the Mail app does), use the selectRowAtIndexPath method:

[theTable selectRowAtIndexPath:tempPath animated:YES scrollPosition:UITableViewScrollPositionBottom];


According to the HIG, you aren't supposed to leave table view cells in a selected state. You are encouraged (strongly) to deselect the row as soon as you perform whatever action the tap requires.

For persistent selections, you are supposed to use the accessory, and you can set a cell's accessory to a checkmark to indicate "Selected"

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜