UIPickerView in UITableViewCell showing behind next Cell - ios

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/

Related

UISearchController messes with Layout of Cells

I am using a UISearchController in my application following this tutorial:
Now having set up a custom UITableViewCell. The UISearchController messes with my cells.
It seems like the UISearchController is not using the same custom UITableViewCell and it's view bounds differ from my own UITableView. Is there a way to change this back, when I press the cancel button?
Edit:
Though, nobody has answered, I found a solution:
make sure, your cell is connected to the actual tableView, not your primary only. ( I have used an Outlet and set only the cells of my outlet )
make sure you ALWAYS address the outlets in your custom cell. Since I used this
cell.textLabel?.text = "Hello"
my cell will automatically be cast to the default cell.

UISegmentedControl Selected value is missing in UITableView during scrolling

I have a UITableView with around 15 cells. In each cell, there is a UISegmentedControl.
When user selected a value of UISegmentedControl in the first cell, scroll down and scroll back to the first cell. The selected value is missing.
I found that it called -cellForRowAtIndexPath: frequently. While the cell dismissed from the screen, it will call -cellForRowAtIndexPath: again when the cell is back to the screen. And the selected value of the UISegmentedControl is reset.
I am currently using iOS8, and I don't have any problem with previous iOS version.
Thank you very much.
Ben
Multiple calls for cellForRowAtIndexPath is normal, the app dequeues offscreen cells. Make sure you save the state of the UISegmentedControl and update the segmented control appropriately in cellForRowAtIndexPath the next time it appears onscreen.

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
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.

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: ?

UISearchbar inside UITableView as the last cell hiding the keyboard

I have a UITableView in which I have several custom cells and my last cell contains a UISearchbar in it. I have wired up the appropriate delegates and referencing outlets and can get the keyboard to show up.
The problem I am facing is that the searchbar is at the very bottom of my tableview i.e. it is part of the very last cell. So even though the keyboard gets shown, the searchbar is hidden below it as I suspect it is unable to scroll to that location since its the last cell in the view.
Does anyone have any thoughts on this and how to overcome this situation.
The easiest solution is to have your view controller be a subclass of UITableViewController. This type of view controller will handle issues exactly like these.
If you cannot, you should listen to keyboard will show/hide notifications and set contentInset and scrollviewIndicatorInsets bottom of the table view to the keyboard height. Then you can scroll the specific cell into visible. When the keyboard hides, set the bottom to the previous value.
Yes....Two ways
1) either you can change the frame of whole tableView and pull the whole table up by decreasing the y position of tableView
[tableView setFrame:CGRectMake(100,100,100,100)];
or
2) You can change the contentOffset of the table to programatically scroll the tableView's last cell so that it is visible to the user.
[tableView setContentOffset:CGPointMake(0,400) animated:YES]
Hope this will help you.

Resources