Register multiple header supplementary view in the same UICollectionView through storyboards - ios

So I have a UICollectionView that I want to use to display multiple UICollectionViewCells and different headers depending on the state the user is in. The problem is I can't seem to register multiple UICollectionResuableView (header) views within the storyboard. If I try to register one as a footer and use it as a header the app crashes. I also do not see anywhere in the storyboard to declare the number of sections, which would alleviate the problem. For now I'm having to use multiple UICollectionViews and hide/unhide the collectionview I want to display based on the header I need. Is there a better way to do this, or a way to register multiple header views in the same UICollectionView within the storyboard?

You cannot register more than one header in a UICollectionView in a storyboard, but you can register an arbitrary number of them in code. You should create however many headers as you want in nib files (One nib per header, with the header as the top level object), and register them with your collection view instance in viewDidLoad.
You would do this with the registerNib:forSupplementaryViewOfKind:withReuseIdentifier: method.

Related

Static table cells with detail

I'm trying to make an iOS 'information' or 'guide' app in Swift. I wanted to utilise the Master Detail template so that when the user clicks a cell it will take them to a relevant ViewController with either basic text labels or a PDF file.
From what I understand, Dynamic Cells can be dynamically changed whilst the app runs however I want to set static cells from the storyboard (or programmatically) and their relevant content/PDF files so the user can view each one. I don't want any "new cell" or "editing" functionality.
How can I make this work? I would post my code so far but it's almost identical to the Master Detail template so I don't see any use. I know this is quite a vague question but I need help and don't know where to start.
Any help will be so appreciated!
A static table cell can entirely be created via storyboard. In the storyboard once you add a tableviewcpntroller you can prototype call added to it.You can add as many prototype cells to your table ( not necessarily every one should have common layout). After all cells are added you can assign individual tags to the cells if you need identify these cells from your code.You can add segue from each cells to move to different page.
Let me know if something more is needed.
In Interface Builder set the Content of the table view to Static Cells.
Drag as many table view cells as you need into the table view.
In the controller create IBOutlets for the labels and the other UI elements.
Connect the outlets in Interface Builder.
Rather than using the datasource methods assign the values directly to the UI elements via the outlets.

Swift custom cells layout TableView decision

I need to display a table with in my iPhone app:
neither the number of cells nor the contents are known at compile time, but only at run time.
Views for each cell may differ, one cell has textField and another may have some other view control.
Should I consider Static or prototype cells?
Should I consider tableViewController or viewController with tableview in it?
Any thing I need to consider before I start coding? Thanks in advance
For The issue of dynamic Number of cell at Run time, you can call reload data for table view at any time you have the data source ready.
Prototype Cells should be used with no problem.
Simple Table View will be sufficient for the task.
You have to make cell, either in code or in storyboard, for each type of cell you want, 1 table View can have multiple types of prototype cells, Just name them differently and then make the objects of only the specific cell of which the data is best suited.
It is not that difficult but do handle the data source with extreme care.
Should I consider Static or prototype cells?
If you know all possible subview combinations that your cells might need to display the data appropriately, and they are relatively few, make one prototype for each. for example:
One text field,
Two labels,
One image view and a label,
...etc.
Otherwise, just use the plain-vanilla UITableViewCell (no subclassing) and remove/add subviews at runtime when reusing them (that is, inside the method -tableView:cellForRowAtIndexPath:).
Should I consider tableViewController or viewController with tableview
in it?
The only reason I would choose UIViewController + UITableView over UITableViewController is if -for example- I needed the table view to only take up part of the main view's bounds/screen, and display some other subview in the remainder. Otherwise, you get so much "for free" with UITableViewController that there's just no point in implementing all of that from scratch.
You have to choose prototype cell, u can create different types of cell depending upon your requirement.Any think ok for u, u can create tableview controller or view controller.

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.

Custom UITableViewCell using storyboard with some cells

I have a TableView in which a most cells are pretty standard. I make them buy using static cells in Storyboard. However, one cell I would like to customize probably using an XIB file so I would need to load it programmatically.
In the TableView's data source, is it possible to handle loading XIB view for this particular cell only, while leaving other cells to what's delineated in the static cells in the Storyboard? Or is it an all or nothing thing where I need to just give up using static cells altogether?
The rationality for doing this is that I would like to make Storyboard to look as close to the real thing as possible. Right now if I provide a data source, the static cells in the storyboard would have no effect on the actual output and is not in any sense linked to the actual output.
Yes, it is possible. Set the custom class for the custom cell. If you wish to customise it from code, just connect it as an IBOutlet to the UITableViewController.

Setting up a tableviewcontroller with multiple sections and buttons

I would like to know how to develop an IOS Table View Controller with multiple sections.
For example attached is a screenshot from DrawSomething account page. They have different headings like account settings, password, then some buttons below.
Would this be setup as one UITableViewController then setup image backgrounds for the headers and customized cells for each table cell, or would this be setup using multiple different view controllers all within one main view controller?
Further to this, could this be setup and designed using a NIB or would it be alot easier using code to generate this. I understand that it the choice of the developer and your opinion but in common practice if it is possible to design (as such) within the NIB it would be easier. Although designing a table view layout in NIB does not appear to be possible...
For something like this, since there's nothing really dynamic about the content, I would use a UIScrollView and just place the various elements on it directly.
Looks to me like each "section" of that table is actually a custom cell. The "heading" of the cell is just a label with textFields place in it etc...
Get a UIImageView to back the cells and you're good to go.
I've done stuff very similar to this using Interface Builder.
Make each cell use a different reuse Identifier so that when you load the table you know which cell is which.
You can create a table view with multiple sections. You need to create custom cells for headings and the contents.

Resources