Customise rows in sections for UITableViewCell - ios

Most social network apps using UITableViewCell I've observed have a minimum of 3 rows in each section. The rows come in different sizes, with usually the first row containing the users details and the time they've posted the content. The second row contains the content posted with an image or text, and the last row contain further options such as the like button, follow button, share button, etc.
What is the best way to create such a cell?

What I would do is I would create a custom cell in an nib file and then in the custom cell .Swift file all you would have to do is declare all the outlets. To implement this custom cell I would recommend taking a look at this stack question Custom UITableViewCell from nib in Swift

Some approaches:
Footer and Header
Section: users details and the time
cell: content posted with an image or text
footer: further options such as the like button, follow button, share button
Only Cell
You can do it using only cell. You can create a base cell (title [details and the time] and bottom buttons[like button, follow button, share button]) and subclass 2 others: image cell , text only cell , etc..
Many tables (worst option)
You still can use this option. Basically you will have 1 section for each post and inside this section will have one UITableView (with 3 cells[header, content, footer])
I have been using "Only Cell" approach

Related

Move CollectionViewCell to another section

I have a UIViewController with a collectionView inside it. The layout may seem confusing but I am making use of horizontal scrolling UICollectionViewCells, presented in 3 sections.
The main collection view is made up of 3 sections. I access 3 different UICollectionViewCell classes for each section becuase it is fetching different data for each one. Once the data is fetched, it dequeues another Cell class, which is the same one accessed for all the sections.
There are 2 buttons in each cell. When I press the button, a value changes within the database. When I re-run the program, the cell in which the button was pressed has moved to its corresponding section that it should be in as per the change. However, I want to achieve this as soon as I press the button. How can I move the cell from one section to another, baring in mind that they the cells presented are inside a collectionview cell making up the sections, which is then inside a greater UICollectionView.?
I've tried researching how to do this but no luck, and everyone seems to be using a drag and drop method which seems too complicated for what I am trying to achieve. Would appreciate any help.
Thanks
The approach I followed to achieve the above situation is using a custom Delegation when cell is removing from collectionviews. A container CollectionView has two sections with 2 different cells containing two different Horizontal UICollectionViews. These two collectionview's cells have UIButtons. When tap on one collectionView's button, that particular cell is removed, custom Delegate method calls and another CollectionView's cell is populated. This is the link of the project I have created for this particular scenario. For better understanding, here is a GIF for demonstration.

Custom Cell merge in UITable view

I am working with Custom cell merge functionality in my UITableView.
I have Table view with 3 different column. First column is for username, second is for Facility that is provided to user and last is for the permission that is given to user for the particular facility. And currently my Table view shows as follows:
As you can see in the above image the Username cell is repeating, if username is same for different facility. So it's not looking what I want.
I want to merge Username cell column to stop repetition. And want to merge cell as below given image.
I got count of Different Username which is repeat in database table with NSSet but i did not get clue how to merge this cell.
Please help me for this and provide some sample code for the same if possible.
Thanks in advance.
TableViews are single column. You may have to use 3 TableViews to achieve your UI.
If you use 3 TableViews - all you need to do is set the height of the cells in the first tableview (User) as multiplers of number of respective rows in the second tableview (access).
For example, the height of 'User 1' cell would be 5 times the height of a cell in the second table (access). The height of 'User-2' would be 2 times the height of a cell in the second table (access).
The best way is to use a section.
But still if you want to make UI like that, then the process is as below.
If you have data like in 2nd image then you need to create 1 row for 1 user.
Then you need to create 2nd and 3rd column, by dynamically.
i.e. if User 1 has 5 row, then you need to create 5 Custom view in User 1's Cell programatically.
Then you need to manage height of cell also programatically.
i.e. if User 1 has 5 row, and you take height of 1 row is 50 then you need to make cell of (5 * 50) = 250.
You can achieve this output by taking only single UITableView.
Create your UITableView as shown in image.
Follow below steps to get the desired result.
================================================
Create a UITableView with dynamic row height. (using
UITableViewAutomaticDimension)
Create a UITableViewCell as shown in image like Left side is UIView containing UILabel as User.
Create UICollectionView for right part of your TableViewCell containing two 2 columns for facility and permissions.
Disable scrolling for the CollectionView.
Give Height Constraint to the UIView (UserView) created above.
Now to populate your tableview:
Get the number of count Facility for every user and set Height of the UserView as:
facilityCount * CollectionViewCell item height
By this way you can achieve your output in very efficient way without any multiple scrolling issue.

set height of outer TableViewCell from inner nested UITableViewCell

I'm trying to implement accordion view using UITableView. I want nesting of the view up to 2 levels.
(Example : There are multiple Regions under Each Region there will be zero/multiple Locations and under Each Location there will zero/multiple Users).
For implementing this scenario I used nested UITableView. i.e Outer TableView (i.e Region TableView) will have its cell as another UITableView (i.e Location TableView) and Each cell of LocationTableView will have another UITableView(i.e TableView Showing users list under each location) as its cell.
I have attached the images for more clarification.
In below image Regions are sections of the tableview. (note : not a single row for now in tableview)
After Tapping 2nd section i.e section with name Region I dynamically reload that section and add the cell(i.e the cell that contains the UITableview showing the locations)
But, it shows the empty space below the location tableview.
Instead I want something like this as below :
Again after tapping the 0th section(Location 0) of the inner tableview (i.e tableview containing location list) I dynamically reload that section of tableview and add the cell(i.e the cell that contains the UITableview showing the list of users under that location)
Have a look at below image
It works perfectly.
Now my issue is that I have calculated the height of the outer UITableviewCell in *- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath )indexPath method depending on the number Location within That Region(i.e Cell) and number of Users under each Location under that Particular Region cell. Issue is that I need to hide/show the locations and users list(All the locations and users list is not shown at once)as according to accordionView. So the height of the inner tableView increase/decrease, hence leaving the blank space at the bottom. Also I have created custom UITableViewCell (i.e creating separate nib file for the cell) for each inner cell containing tableview as ContentView and implemented all the UITableView Data Source and Delegate methods in its corresponding .m file.
What I want is not to show that empty blank space.
When control goes in the inner tableview cells I can't set the height of the outer UITableView from there.
Hope you understood my problem. Please help me. Thank you!!!
I had some similar requirements like this, I didnt use the nested tableview as it brought some complexities to me, so I tried playing around with indentation and indexpaths of the tableview to achieve what I wanted. I just did a small sample app with that concept with some dummy data. I have never tried this approach with Custom cells. See if this helps.
I know I am not answering to the exact question that you asked but I am trying to give a different approach which for me looked simpler.
I just modified my base code to match your data
How to create an Accordion with UItableview under a UItableview?
The source can be found here
Accordion
Screenshot
-anoop

header cell on top of list

I have a tableview with a list. I want to add a cell to the top of the list that shows what is being displayed below. So each item in the list is a Name with Age and Gender next to it. I want a header cell on top that actually says "Name Age Gender" so that people actually know what data is being displayed. I also want this cell to not scroll when the rest of the list scrolls downwards.
Do I add another cell to show these things or should I do it via another method?
I think you're talking about a header of a table view section. If so, you can implement the header cell methods in UITableViewDataSource:
-tableView:titleForHeaderInSection:
Alternatively, if you want to get fancy and use your own view for a section header try implementing the UITableViewDelegate method:
-tableView:viewForHeaderInSection:

Adding cells to UITableView when all cells are static (designed in storyboard)

I have a UITableView with 5 sections. All sections contain 2 static cells. What I want to achieve is to insert a new cell to one of my section when user taps some button. I know how to add cells with animation when UITableView contains only dynamic cells, I have no idea how to do this with 100% static UITableView.
The point is to that in one of my cells I have a text input and a button. After user taps the button, input content must be validated. If validation fails then I want to add an extra cell with error info.
Thanks in advance for your help!
Here you able to find how to add static cells using story board.Show configure table view as static cells and create outlets according to your app design.

Resources