UITableView : click in blank area will not trigger didSelectRowAtIndexPath - ios

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

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.

Related

Can I make only a certain portion of a tableview clickable?

I'm trying to add a like button in a tableview but If I click anywhere in the tableview, it immediately goes to the detailsVC. I want to make it so when you click that like button, only that is selected. Is there a way to make it so only the top half of the tableview can be selectable or have interaction enabled, and put the button below? Or is there another way to do this. Is there a workaround or a method I am missing. Thanks
Are you sure the UIButton is added correctly to table view cell's .contentView?
Can you see it? If so it will intercept the touch events and tableview's delegate didSelectRowAtIndexPath won't get called (even if there's no handling connected to the button). If you want make the button occupy specific area of the cell you can either:
Design your cell in Interface Builder and make it a part of Storyboard/Xib
Do autolayout of the cell programmatically
Override cell's layoutSubviews and manually setup the frames

TableView Cell Not Showing Content and Not Responding To Commands

When working in the storyboard I can add labels and imageviews to a tableview cell but when I run the app they will not show. The only way I can get them to show is if they are in a stackview on a view within the cell. The cell will only not change colors on run time even if the cell's background color is changed in the storyboard. Is there any way I can fix this?
You should give us more insight to your project - that means your code, possibly your storyboard...
It's hard to tell what you did wrong when we even don't know what you did.
Did you connect your objects with outlets?
If you defined your own cells, did you selected them in storyboard?
How about your TableView Delegates?

UIPickerView in UITableViewCell showing behind next Cell

I have a tableview with a number of custom cells. The problem I am having is that the cell with the pickerview is 'bleeding' behind the neighboring cell.
Once I push another view controller and pop back, the neighboring cell is properly opaque until I manipulate the picker, at which point the issue materializes again.
The cell is, in fact, opaque. I have set it as such in both the storyboard and code. I have also tried setNeedsLayout and layoutIfNeeded in cellForRowAtIndexPath.
Set clipsToBounds property to true to each cell in the method cellForRowAtIndexPath.
You can set this property in the Storyboard if you are using prototypes cells.
You need to provide more information.
But if I understand correctly, you should hide the cell that contains the picker and only show it when the user will input.
Here is a tutorial on how to hide the cell, like the calendar iOS app does.
http://www.appcoda.com/expandable-table-view/

Disabling touch interaction of Spaces between Custom table view cell

I use custom cells of subclassing UITableViewCell in a table view. And There must be space between cells. I succesfully add the space with adding a subview that I called SpaceView into the content view. But When I touched the spaceView, it is perceived as I touched the cell. And didSelectRow method called. I tried to set spaceView's UserInteractionEnabled==NO. But It doesn't work.
So my question is; Is this the right way I used to add space between cells ? Should I try to add cells for making the space ? or If its the right way, How can I prevent calling "didSelectRowAtIndexPath" method when I touched spaceView ?
like Inder said below, u can use an UIButton to solve the issue.
1) in your custom cell: at the bottom of your custom cell add a blank UIButton with the height u actually need between cells, and customize its background color according to your needs.
2) in cellforrowatindexpath: disable button of each cell. (or you can also do that in Interface Builder of previous step)
result: u have a clear disabled button that will appear as required space between cells.
Make your spaceView as UIButton (I guess it's UIView right now)
When you add UIButton that touch will be consumed by the button thus touch won't be passed to it's parent.
OR
I'm not sure if it will work or not, you can add tap gesture to your spaceView

How do I get selectRowAtIndexPath: to work with willDisplayCell:?

First off I have a custom tableview subclass that uses a uiview subclass with drawRect: to handle the cell's content view. Now since I need a the cell's selected to be a certain color I set the cell's selectedBackgroundView in willDisplayCell:
This works great until I need to scroll to and highlight/select (but not call didSelectCell) upon showing the tableview. When I try to call selectRowAtIndexPath: the tableview scrolls to the cell but the selected color is only shown in the cell where the contentView isn't (by the disclosure arrow).
Now I believe this is because selectRowAtIndexPath: highlights the cell then scrolls to it. And willDisplayCell needs to be invoked before the cell is highlighted. However willDisplayCell is called "only when animating rows as they slide in or out" i.e. after the highlight and before the scroll.
I confirmed this by calling scrollToRowAtIndexPath: then a selectRowAtIndex:animated:scrollPosition: wrapped in a perfomSelector:afterDelay:
How do I fix this without using perfomSelector:afterDelay: ?

Resources