UISearchController messes with Layout of Cells - ios

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.

Related

The separator of the last tableViewCell will not be displayed when the UITableView is added to the footerView

The separator of the last tableViewCell will not be displayed when the UITableView is added to the footerView.How can I make it be displayed?
enter image description here
I believe you have no other choice than making a custom UICollectionViewCell and manually add the separator inside as an UIView.
This is rather straightforward if you're using a storyboard as you can directly design your prototype cell inside.

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/

UIFooterView not showing when using deque Reusable cell with identifier to get UIView

I am trying to add a footer to my UITableView. I was able to do this programmatically by making a new UIView with the desired height and width and setting the tableView's tableFooterView to this view.
However, I want to use a reusable tableView cell as my table footer. I tried to set the property as follows
myTable.tableFooterView = myTable.dequeueReusableCellWithIdentifier("footerCell") as UIView!
However, the table View does not show up. I was able to get it working when implementing the tableViewforSection delegate method. However, I realized that I need a table footer and not a section footer, since I'm effectively trying to create a custom last cell for my table that scroll with it.
PS: I checked the identifier for my footer cell in storyboard and it looks correct. I also tried creating a custom class for my custom cell and setting the storyboard cell to be of that type, but that doesn't work either.
If you want to use a cell for your footer, and you're using an array to populate your "regular" cells, then return the array.count + 1 in numberOfRows, and put an if clause in your cellForRowAtIndexPath to check if indexPath.row == array.count. If so, dequeue your footer cell.

Label text in UICollectionViewCell not updating

I'm trying to change the text of a UILabel in a UICollectionViewCell after the UICollectionViewCell has loaded, when tapping a button. But the label doesn't update on the screen. The console shows that the text property of the label is updated, but it seems the label isn't redrawn with the new text.
Is this a known problem with UICollectionViewCells? Some kind of caching issue, perhaps? Do I need to reload the cell, or the entire collection view for the update to show?
I had a similar situation where a UILabel in the collectionView cell was updating fine. Then after making some modifications to the storyboard, the UILabel would not change when updating the value programmatically. As noted in the initial question the value stayed the default value even though the debug terminal showed that the connected UILabel attribute text was being updated.
Here is how I resolved the issue. In the storyboard,
Deleted the referencing outlet for the UILabel (in the "Show the connections Inspector")
Deleted the UILabel from the storyboard
Re-added the UILabel
Reconnected the referencing outlet to the swift file code attribute
And somehow, everything started working fine again.
As a side note: The swift 3.1 versions of Radwa's answer are:
collectionView.reloadItems(at: [indexPath]) // single cell in the collection view
collectionView.reloadData() // entire collection view
Because the cell is already loaded, no change in cell will happen until it's reloaded, so you can either reload the entire collection view
[self.collectionView reloadData];
Or just one/multiple cell(s) that got affected with that change of data
[self.collectionView reloadItemsAtIndexPaths: indexpathArray];
But make sure that you change the data properly before reloading the cells

Using a Custom UITableViewCell with Prototype Cells

For reference, this tutorial I am following: http://mobile.tutsplus.com/tutorials/iphone/customizing-uitableview-cell/
I have to create a custom UITableViewCell, and from the tutorial, it said to leverage Prototyping cells and subclass UITableViewCell. Then connect the UI elements in the prototype cel to the custom class (of UITableViewCell).
The problem I am running into here is, there is only one cell for the whole table view that is displaying data. However, I am able to click on empty cells in the background behind that one cell that contains data. If i scroll up or down, cellForRowAtIndexPath is called and another cell gets displayed. However its only displaying once cell at a time for the whole table view.
Does anyone know what the problem could be here? Any help is appreciated, thanks!
Figured out what the problem is, my labels (that are supposed to be inside the custom prototyping cell) were added to the parent view and not the content view of UITableViewCell. This is because my prototype cell did not have a content view for some reason. I had to add a another prototype cell and delete the previous one.
reference: How to add subviews to a custom UITableViewCell in a storyboard

Resources