Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView : click in blank area will not trigger didSelectRowAtIndexPath

When I am developing iOS8 Today Extension, I set a UITableViewController as the main view controller.And I met this problem:

When I init the UITableViewCell using initWithStyle:UITableViewCellStyleDefault in cellForRowAtIndexPath, the whole area of one cell can trigger didSelectRowAtIndexPath normally. However when set UITableViewCellStyle to UITableViewCellStyleValue1, UITableViewCellStyleValue2 or UITableViewCellStyleSubtitle, I can only trigger didSelectRowAtIndexPath by click in detailTextLabel or imageView's area. Click in other blank areas will get no respond.

I've tried to set tableview's delegate to self, set detailTextLabel and imageView's setUserInteractionEnabled:false in cellForRowAtIndexPath, and all these do not work. Does anyone have any idea about this?

P.S. I am not using storyboard or xib file,just code.

I've found a same problem on Android: I'd like to click anywhere (blank area) in a list view

like image 656
CodeRain Avatar asked Sep 01 '14 12:09

CodeRain


1 Answers

I encountered this myself while trying to display UITableView inside the TodayView. Although I don't know why is this happening, I found out that this only occurs when the UITableViewCell background is clearColor. If you set the background to some other color, didSelectRowAtIndexPath will be called. However, here's a quick workaround - put UILabel to stretch on whole area of the cell's contentView and then the delegate method will be called every time. Anyway, it seems like a bug.

like image 116
niknovak Avatar answered Oct 28 '22 13:10

niknovak