I dragged a tableView to my controller in storyboard. I set the type to grouped, but I don't know if I can set the tableView's section number in storyboard.
I can not see the tableview's content to Static Cells. If I do this it will report error.
You cannot do that in tableView because it does not support static cells.
However if you use TableViewController
you can create static cells and you can create your desired sections and as well as add section number too.
Table View controller gives a more flexibility than Table View alone.
Related
There is a main table view and inside each of the main table view cell has their own header table view. Then each of the header table view cell has their own sub-header table view. All the table rows don't have fixed counts according to the dynamic data. What I try to achieve is when a cell of the main table view is expanded, I should see the header table view cells unexpanded. After a header table view cell is expended, I should see the sub-header table view. I need a solution without using libraries.
I provided the storyboard UI based on what I want to achieve.
To deal with expandable cells (or cells inside cells effect) I recommend using UIStackView inside UITableViewCell and add inside needed views with data.
For example you can create UIView inside Xib file and load it inside needed UITableViewCell then add to UIStackView and fill with data.
Then you can simply hide/unhide elements inside UIStackView to archive expanding/unxpanding.
This way or other you should use 1 UITableView.
I once made a 1 step expandable Table View.
Here is what I did to achieve that.
Do not make different table views for each hierarchy. That will be difficult to manage. Instead, make one table view but change the type of cell you want to show. If the cell is top level cell or first level cell or the second level cell, change the design of each one that.
The data source will then have list of list of list to denote the 2 level expandable UITableView.
To open and close the table view, you can simply change the data source and reload or use beginUpdates and endUpdates
I am working with collectionview inside tableviewcell in Swift 4. I get the content from server which is all dynamic. I have to show different types of collectionview behaviours.
For example, in the first tableview row should be collectionviewcell with screenwidth and scrollable. In the second row, collectionview with 3 sections and each section has different content different number of items.
Here I got stuck I am unable to show 3 sections one below other it is showing besides horizontally. I have calculated collectionview flow layout size.
Also in last row I have collectonviewcell with scrollable content,here when i scoll the content is repeating from bottom row or top row. I want the smoth scrolling and to stop repeating the content.
I am new to Swift. Can anybody help me out of this . Thanks in advance.
The smooth way is to create tableview with its cell xib and inside its cell add collection view and create another xib for collection view cell. This method is helpful when accessing collection view for different tableview cell. Rather using without loading Xib's may mixup your code.
You have to set tableview cell height as UITableViewAutomaticDimension. This will handle your cell height as per your dynamic content.
For each tableview cell you have to set collection view's property by using cell's index path as per your requirement.
I need 5 viewController all of them has the same header components. So I don't want to duplicate the same views and codes for each viewController. I would like to create a header and use the header for each viewController.
The problem is header will be filled by an object and this object has a list attribute. so i need to add this list attribute such a tableView.
What one view controller look like
I am trying to create an headerViewController and pass my object to it. And i will use this viewController in a container view for each 5 main view Controllers. But the height would be different so I can't define a height constraint to container view. in 5 view controller should use scroll view, because the total height will be higher than screen.
It is a little bit complicated because i try to solve this problem such a android developer :)
Assuming you want all items in tableView to be displayed all the time (no scrolling in tableView)
You should add height constraint to tableView or containerView
After loading/reloading the tableView with data set tableViewHeightConstraint OR containerViewHeightConstraint with content size height of tableView
tableViewHeightConstraint.constant = tableView.contentSize.height
OR
containerViewHeightConstraint.constant = tableView.contentSize.height
I have solved this issue creating a main view controller that contains a table view. And the common header is a type of tableviewcell. Then for each different body parts became another tableviewcell so according to type attribute of viewCOntroller, I am loading related tableviewCell.
I did this after #midhun-mp comment. Thanks to him.
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.
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.