How to create 'containers' similar to Facebook? - ios

I'm creating an app that will get data from an RSS feed and I want to know how I recreate something similar to the Facebook app 'containers'
An example of what I mean is below.
How would I go about recreating the boxes where the statuses are held?

To achieve your desire result you have to create custom table view cell using UITableViewCell and arrange views as per your need by creating subclass of UITableViewCell

Just create a UITableView with different prototype cells and then deque the appropriate cell identifier in cellForRowAtIndexPath.

You probably have to subclass UITableView for achieving the desired effects such as indentation etc.
After that you have to make custom view for each cell and return them from the method cellForRowAtIndexPath

Related

I need help knowing where to start on designing a tableview or if a tableview is what I need

As in title, I don't know where to start with creating a view like this. Do I hard code it or use XCode editor? Is a table view what I need?
Yes, a UITableView is what you needed.
You need to create a TableView Controller.
Follow by creating a TableViewCell
Then you need to start coding. Hook up the delegate and data source methods.
For more information, check this tutorial by Apple:
https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/
Here you have a tableView with section header indicating the date of the matches, the tableView has a custom designed cell, each cell contains the names of the two competing team.
start by adding the tableView to your viewController using storyboards, with the delegate and datasource connected.
the sub class from UITableViewCell and create your custom cell with an xib file.

How to reuse UITableViewCells

I have 2 viewcontrollers on my storyboard, which both have a tableview. Now I would like to implement the same cells in both tableviews. Is there a way to easily reuse these cells across multiple viewcontrollers?
Yes you can use it by using custom table view cell
Example for custom table view cell
You should reuse full UITableView for this case. There is no open API for sharing cells between multiple UITableViews, but you still can reuse UITableView in case there is no moment when two controllers are shown simultaneously.
Yes, It's possible you need to create .nib file with subclassing UITableviewCell
take a look on https://medium.com/#musawiralishah/creating-custom-uitableviewcell-using-nib-xib-files-in-xcode-9bee5824e722#.u8xounci2
you get to know , how to create & use .nib file.

How to reuse custom UITableViewCell defined as a prototyped cell in Storyboard controller

I have the only cell template for items at two different UITableViewControllers/TableViews.
What I need is to define it once and then reuse at other UITableView via
UITableView.DequeueReusableCell(CellId);
The issue is that is when I call this method on UITableView which doesn't contain cell prototype I'm getting NULL.
How to reuse my prototyped cell across multiple table controllers?
I want to define cell template in storyboard, NOT xib.
It turned out that the only way to reuse a cell it to design it with xib and register at tableview that xib with cellid.
Just copy-paste your prototype cell in every table view controller where you need it.
And if I understand your question, in a standard and proper way, it's not possible to dequeue a cell from another table view, Apple implementation handles this mechanism itself.
Using xib for a reusable cell is beneficial while cell design is fixed in the whole app. But when there are conditional requirements or slight changes in design or functionality and remaining design and functionality is same for tableview cell, in this case if you still want to reuse the code then you can subclass tableview cell class.

In iOS can a cell in a tableview have more than just a text

Can i have two images and a few text labels in a cell of a tableView ? All dynamically assigned ?
Yes, read the documentation for the UITableViewCell class, specifically the UITableViewCellStyle constants which allow for various types of standard table cells to be created. If the built in styles do not meet your requirements, you can subclass UITableViewCell and create anything you want, since it's just another type of UIView.
Of course you can! There are several ways of achieving that, the most popular being subclass the UITableViewCell class, and creating your own custom cell, and you can have whatever you want in it. But just to get an idea of how to go about doing that, I suggest you go through the following links:
Table View Programming Guide for iOS - Apple
Crafting Custom
UITableViewCells - MobileTuts+

Add an action to a custom UITableViewCell

I am building a simple app with a table view filled with custom view cells and using a storyboard. I want to add a actions on the cell each time the user tap it.
So far, I tried to create an IBOutle to link my cell to my tableViewController and add the action manually in the code but each time I try to do it I get an error message saying "Illegal Configuration - cannot have a prototype object as its destination".
The only quick fix I found is to add a UIButton with a transparent background and no title which fills in the whole cell and attached the action to it.
Is there any more elegant way to do it?
Not only is there a more "elegant" solution, but there is also a correct way to do this.You should be using the didSelectRowAtIndexPath method for your cells.
You should read what the Apple Docs have to say
And also, here is a tutorial on how to use row selection in your tableView.
The elegant solution is to use your table view's delegate method tableView:didSelectRowAtIndexPath: and put all your action code there.

Resources