What is the alternative to static style cells in storyboard? - ios

I cannot use static style UITableViewCells because of the storyboard restriction that the underlying controller must be a UITableViewController.
So how can I achieve the UI layout like the 'new contact' screen in the ios Contacts app?
In particular the phone numbers/email ('mobile', home) input: is there any existing API that draws the thin vertical divider? Or I have to create a nib?

I've seen this done by having the top three fields be fake. Use a table view header which has the image view and the First/Last/Company be simple textfields. You put a pretty picture that looks like table cells behind First/Last/Company.

Related

Should I choose ViewController or TableViewController?

New to Swift. I am trying to write a recipe-sharing app for fun. One of the features is to let users create a new recipe. On this page, users should be able to give an intro to the recipe to be created, upload an image THEN add a LIST of ingredients dynamically (as we have no idea how many ingredients in total beforehand).
I have created a UIViewController, which includes a UIViewTable, an image view and a "add another ingredient" button. I have created a class for the ingredient. And when the "add" button is pressed, a new "Ingredient" cell will be added to the table. However, I found that adjusting the UIViewTable height dynamically is quite hard.
I want my table to adjust its height according to the number of cells (rows). I haven't found much useful info online.
Or maybe I should've not even used this structure. Instead, just use UITableController (The entire page is a table)? But I got confused that some of the elements (image view, submit a recipe button, recipe-intro textfield etc) will be only created once. Why do I bother making them as prototype cells and add them to my view programmatically?
Thanks in advance!
First of all, welcome to Swift!
You put a few questions together, I will try to answer them one by one. Let's start with the simple stuff.
Don't try to change the height of UITableView based on the number of items. If you want to achieve similar functionality, take a look at UIStackView. Set fixed size for the tableView, ideally with constraints using auto layout.
UITableView is supposed to fill specified space and scroll items inside or show cell on top if there are not enough cells to cover all space.
UITableView is highly optimized to scroll over huge amount of cells as the cells are reused on the background. If you are new to the iOS world, take a look at this function https://developer.apple.com/documentation/uikit/uitableviewcell/1623223-prepareforreuse it can save you hours of debugging (I have been there)
UITableView vs UITableController
UITableController can save you a few lines of code, but using UITableView inside of UIViewController can give you more freedom and save you refactoring if your app is likely to change in the future. There is no specific advantage of UITableController
If you want to provide the extra elements (image view, submit button, text field etc), you can use several methods and this is where the UIViewController with your own UITableView comes in handy.
You can put some buttons, like a plus icon or "Done" button into the navigation bar, as the native Calendar app does.
You can put the static content (intro text field, image view) above the table view (visible always). Use constraints to place the static content on the viewController.view and constraint the table view under your static content. The table view will take less space on the view keeping the space for your content.
Insert your static content as a table view header (will scroll out with the content). Search "HeaderView" here on stack overflow to see how to achieve that.
Place your content over the tableView. If your button is small (rounded), you can place it over the tableView, eg. Twitter uses this for a new tween button.
Hope this answer your questions. Cheers!

Emulate a table cell without needing a UITableView (re-using standard iOS UI)

I'm creating a settings/edit profile view in my iOS app, which has a mix of text inputs, and cells which simply push a new View Controller onto the Nav Controller stack, ie.
However, to me that looks like a standard UITableViewCell with an image view on the left and an accessory view on the right. Could I leverage this control for my View, without needing to create a whole UITableView? Obviously I could re-create this with UIImageViews and UILabels but I was wondering if there was a better, more efficient way of creating this UI?
I have often implemented such screens easily directly in my storyboards with static cells. Agreed, you need a tableview, but you get all the advantages (e.g. scrolling if the keyboard covers up any cells) practically for free without any additional code. You just write what you would write if you would recreate the interface with labels and image views and such.

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

What controls does the built-in contacts app use?

In iOS, the built-in contacts app looks similar to what's displayed on this example page. What controls are being used to create the initial view? Is it a table view? If so, how is the image on the left offset from the two rows?
What's happening behind the scenes to switch this view into edit mode? Are labels being replaced with textboxes or are the textboxes simply being set to editable?
There are 2 ways to do things like this that I know
#1. That is UI TableView, but TableView with a custom TableView Header.
Also it is UITableViewStyleGrouped
Just Init and setup the view include a UIImageView On the left side and three UITextField on the right side.
like this
|----------| |---TextField---|
|---Image--| |---TextField---|
|----------| |---TextField---|
and set this view with:
self.tableview.headerView = yourViewWithImageAndTextField;
2. Just try to use Apple's own ABPersonViewController
Apple's sample
Documentation
Good luck to you
This looks like an pre iOS7 UITableView in UITableViewStyleGrouped style, and a probably a custom cell to handle the image.

How to replicate ABNewPersonViewController layout

I'm trying to create a layout very similar to ABNewPersonViewController that will allow a user to create a new contact in my app. My app doesn't use AddressBook nor would it need several of the fields in the ABNewPersonViewController, so I'm trying to replicate the layout of ABNewPersonViewController in a storyboard.
I'm settling right now on the following solution...
View Controller
View
UIButton ('add photo' button, left-aligned)
Table View (~85% width to allow for 'add photo' button)
Cell w/ text field (first name)
Cell w/ text field (last name)
Table View (100% width)
Cells w/ remaining details
First, I'm curious if anyone has any suggestions on a better layout.
Secondly, I don't know how the vertical border can be implemented for certain cells (e.g., phone number has a left detail w/ the type [mobile, home, iPhone] and then text field at right w/ the actual number). Any ideas?
The contact picker looks to me like a UITableView that uses grouped cells. Each of the groups has that rounded look around it.
There are different types of UITableViewCells that are provided by the iOS SDK. The one that you are describing is called "Left Detail" in Interface Builder and programmatically is called UITableViewCellStyleValue2. You can set each cell individually based on what you want in the UITableViewController cellForRowAtIndexPath method.
EDIT:
A possible way to create this in IB is to create a UIView and then add an image container and two table views to it.
UIView (Primary View)
--> UIImageView (In top left corner.)
--> Grouped UITableView (In top right. Contains first, last, and company.)
--> Grouped UITableView (Below the above two items, goes across the screen. Contains the rest.)

Resources