Using a Custom UITableViewCell with Prototype Cells - ios

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

Related

iOS UICollectionView switch cell NIB dynamically

I am updating my iOS app from table views to collection views to support a "gridded" option.
I have two cell types. One that is more suitable to a "tableView" type look, and takes up the full width of the screen. The other is a cell that is more suitable for grids.
I can't use the same cell type for both because the tableView type cell has a lot more horizontal information than the grid cell.
I have a button press event that will cycle between my cell types, updating the layout and changing the cell reuse identifier appropriately. The problem is, any cells that were already in view do not change to the new cell type. If I scroll for a bit, the new cell types start coming in.
I imagine that this has something to do with the dequeue function for collectionView taking an indexPath. I can explicitly reload those cells to get them to use the new type, but this causes an unwanted animation, not to mention feels like a hack.
How can I switch cell types dynamically?
Linked is a video demonstrating the issue.
https://imgur.com/1Q0Xu9S
As you can see, after I change the cells they remain using the old NIB (with all the extra information). But if I scroll down the new NIB will be used.
There are two solution for this: -
Use two collection view for each type of cell, hide and show respective collection view on click of button.
Remove the collection view from super view on click of button, add again and reload

Can we add tableview to cell?

I want to customize my tableview. I want to add another tableview in cell. Can we add tableview in cell of another tableview?
Please give me some ideas.
You can embed a UITableView into another UITableView's cell, but due to potential issues with the embedded UIScrollViews it is not recommended.
If you feel like you need a table in a table, first consider if it is not possible to achieve the desired behavior by using sections and cells in the sections (a section in a table might represent the top tableView's cell, and cells in the given section would represent the embedded tableView's cells).
There is no problem with adding a UITableView into a a UITableViewCell, since both of them are UIViews its simply would be translated to adding a subview to a view...
However, keep in mind to consider the following issues:
1- From a user experience perspective, that would be a vertical scroll view inside another vertical scroll view (are you ok with that?).
2- For each cell -in the main container table view-, you would need to handle the table view delegates/datasources. For understanding the logic of how this could be done, you might want to check:
Is it possible to add UITableView within a UITableViewCell.
Putting a UICollectionView in a UITableViewCell in Swift: although it is about adding a UICollectionView inside the cell, it helps to gain the logic of how to achieve such a task.

Uitableview with UICollectionviewcell and UITableviewcell

i need to create below design
I am following this code to draw simple collection view with horizontal scroll inside a UITableView
Current sample code work like this
UITableView-> UICollectionViewCell as cell with horizontal scroll
What i want
i want : First row with UICollectionview with horizontal scroll and
Then rest row with Normal UITableviewCell to show data
How can i do it .
add a UITableView to your view controller and implement it's delegate and datasource methods .(You can use UITableViewController instead of UIViewController).
for the fist cell of the first section in your tableview, you should use a custom tableview cell.
Inside this custom tableview cell, you have to add your collection view with horizontal scroll, and implement its delegate and data source methods inside your custom tableview cell class.
these are the steps you have to do.
refer this implement uicollectionview inside uitableview question for more.
Hope this will help to you.
You should design a UITableViewCell which has a UICollectionView inside, and set this cell for the cell in section A and for Section B, you should design a new UITableview cell.
When tableview's cellForRowAtIndexPath call you can check for First section and when first section load you can create new UICollection view object load in first cell. Than next section will load you can work as normal tableview work.
Not- you need to implement UICollectionview delegate and datasource methods also.

Each cell with different layout in TableView, how is scroll optimised?

If I have a UITableView with each cell having a different layout. For example, cell 1 has one text field, cell two has two text fields and so on, in this case height of tableview cell varies based on how many text fields it has one below the other. For this specific scenario, will I be able to make use of reuseIndetifier and reuse the cell.
Is tableView reuseIdentifier useful only when layout of each cell is same? Or can I still reuse cells by making use of single identifier but adding textfields in cellForRowAtIndexPath dynamically?
I experimented a bit. I can do some basic reuse of cells by having a cell with empty template/blank cell. But in the cellForRowAtIndexPath I can dynamically create text fields and add. This works perfectly fine, allowing me to add as many number of views required to be added to TableView cell. I am using blank cell, which will be reused on scroll. However I am not sure that will be the impact on performance when I create and add UI elements dynamically to the cell in cellForRowAtIndexPath. Any ideas there?

UITableViewCell is not available in XIB file in XCode 5

I have just encountered a problem today that I am unable to add a new table view cell to my UITableview.
What I did was I drag a table view cell and drop inside the UITableview area. The UITableview did not take the table view cell but rather the cell become an individual view of the main view.
Clearly see that table view cell is not included in Table View
So my question is, how to create a custom table view cell in UITableview in an XIB file in Xcode 5?
Thanks in advance!
If you have dynamic prototype cell will be added automatically. If not, you can choose how much cell you want to have in inspector on right side of screen.
And make sure when you put it into screen that is inside of your tableview.
I answer this question thinking you are using storyboard. First add UITableView.
Then you can see as this,
If you want to use static cell, select Table View & in Attributes Inspector , in content select Static Cells. I think for your question you should use Static Cells.

Resources