how do I set up a table view in interface builder for a 'settings' type interface - ios

So I guess the table view has been designed around the idea of using dynamic data received at run time, but I want to make a settings type app where all of the cell values are known as I build it, so I was hoping to be able to set the section / row configuration, labels ect, as well as the properties for each cell (whether it has other views inside it like a switch, or whether it is a button etc) all in interface builder.
can I do that? how?
I am using xcode 4.4.1

To use static cell content you have to make sure that you are adding a UITableViewController not just a UITableView dragged into a UIViewController. The latter requires dynamic prototypes.
Once you've added the table view controller to your storyboard it is as simple as selecting "static cells" in the attributes inspector. From there you can drag and drop UITableViewCells and modify them as you wish.

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.

How to layout complicated view with lots of tableview cells and autolayout constrainsts where storyboard is failing

I have a view like this
Basically it is lots of static tableview cells , where each cell has horizontal scroll views and stack views. Now trying this in storyboard has slowed down it completely, where adding or deleting a constraint or just changing label text in Xcode 9 takes more than 30 seconds and there is always a spinning beachball.
What are the ways I can reduce system overload or make storyboard a bit faster.
Or is it better to move to laying out views in code. In that case any help / advice in this regard will be highly welcome.
Thanks in advance for your efforts.
Here is the link to GitHub repo for the same
You should use a few prototype cells, instead of repeating static cells that are virtually identical. You have at most 6 unique types of cells here. For example, Inputs A, D, E are the same. Inputs B, C, F are the same.
It's beyond the scope of the question to explain how to do this in detail, but the basic procedure is as follows.
Let's say you want to add a prototype cell that you can use for Inputs B, C and F. This is your most basic input cell that will have one text field.
Add to your project a new class that inherits from UITableViewCell.
Name it something like BasicInputCell.
Open your storyboard, select your table view and open the Attributes inspector. Increment the Prototype Cells setting by 1. Xcode will add a prototype cell to your table view in the storyboard
Select the prototype cell and open the Identity inspector. Set the Class name to the name of your cell, BasicInputCell.
Open the Attributes inspector and set the Identifier to the same value so that you can dequeue it by this name.
Add a text field to the cell in the storyboard. Open the Assistant Editor and Control drag from the text field to your class to create an IBOutlet.
Repeat for as many unique cell types as you need. Customize each cell type with different controls on it, such as date picker, as needed.
In your table view controller, dequeue the cells of the type you need based on the index path.

View Polymorphism in iOS

What is the correct way to do view polymorphism in iOS? For example, I have custom table view cells that need to contain either a custom BarChartView or LineChartView. I decide at run time whether the table view cell will hold a line or bar chart. Ideally, I want to only create one xib file for the table view cell that layouts the bar/line chart view with other things (like labels for chart title, etc), and I can decide at run time whether the view that holds the chart is going to become a BarChartView or LineChartView. Is it possible to set the morphing view in the xib file in Interface Builder to be one of the superclasses, for example UIView, and then later programmatically decide which subclass it should become? If so, what's the best way to do that?
Step 1. Make two view in custom cell xib file for BarChartView or LineChartView.(Both in single xib only)
Step 2.Write conditions in cellFoRowAtIndexPath to get either BarChartView or LineChartView view to Show.
Note:- Now,there might be condition ,weather to show/hide tableview ,depends on you.
But once tableview need to be displayed, use Step 1 & 2 to dynamic view loading.
maybe have a custom view inside contentView of your cell and just add barChartView or lineChartView to that view. So, even If you need to support more Chart types that'll be doable

Drag UITableCell onto UITableView

I'm fairly new to iOS development and want to create a simple form using a grouped UITableView with UITabelCells to lay-out the form's contents. I want to do this interactively in XCode5.
My problem is, having added a UITableView to the xib, I can't edit its contents in XView. I had anticipated being able to drag UITableCells onto it. Is this possible in XVIew, or do I have to create the table's contents programatically?
You cannot directly edit tableViewCells inside the TableView using xibs. It sounds like you want to use what are called prototype cells. These can only be created using storyboards. Here's a tutorial for prototype cells:
http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1
From iOS 5 and above Storyboard are being primarily used to design the app interface rather than xib.
With your view controller opened in storyboard you can define how the cells looks like for the tableview ( prototype or static content based)
Here is one example
You can read more on it in the docs
https://developer.apple.com/library/ios/documentation/userexperience/conceptual/tableview_iphone/TableViewCells/TableViewCells.html

Why can't I edit multiple dynamic prototypes in UITableView?

I'm creating a Table View in Interface Builder (Storyboard). I'd like to have a couple of different Dynamic Prototype cells with different sets of Labels and Images in them and so on, and I can give them different reuseIdentifiers so I can pick which ones I want at runtime.
In Interface Builder, I create several Dynamic Prototype cells in my UITableView, which is controlled by a UITableViewController.
In the first cell, I drag and drop in various views and so on.
In the second cell, IB will not let me drag any views into it? I can resize the second cell vertically, but can't put anything into it at all, either by dragging into the cell or into the object graph in the left-side bar.
If I copy and paste the first cell, a second Dynamic Prototype will appear with all of the same contents, but I won't be able to modify the copied cell (can't add or move subviews). However--and this is strange--I can select the constraints and modify their values to resize and shift objects in the second cell.
As a note, running XCode 5-DP3. Tried restarting it (didn't expect that to help, and it didn't). Otherwise, unsure what to try, and unsure if I'm doing something very braindead, or if this is a bug I need to report to Apple.
So, am I crazy? Has anyone experienced this/can anyone recreate this?
EDIT:
After further testing, if I stick a big UIView into the first cell, and then copy that cell, I can edit inside my added view. (Does this make sense?) I can't edit anything that lies within the second UITableViewCell, but if it contains a UIView copied over from the first cell, I can put new views into that view and move them around and so on. Super-strange.
For the sake of posterity, I'm answering my own question:
The way I solved this was to take a UITableViewCell object from the Object library and drag it onto the UITableView. Sounds simple, right?
The problem I was running into was only if I copied existing dynamic prototypes through Cmd+C & Cmd+V, or by incrementing the number in the Attributes inspector for the table view. The Storyboard Editor wouldn't allow me to modify those ones.
Dropping in new cells from the Object library let me tweak them all separately.
XCode 5-DP6 solved issues with not abling to resize cell's subviews.

Resources