How to replicate ABNewPersonViewController layout - ios

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.)

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!

How to create a complex scrolling view in iOS similar to yelp?

Yelp has this View show up when you click on a specific restaurant or some event:
In the picture above there is the Cascal label, then Write a Review button, then three buttons (Photo or Video, Check in, Bookmark) all in a row, then a map, and some cells underneath (Directions, Call, Explore the menu, etc.).
How can you make a complex scrolling view similar to this (do you have to use a collection view or table view?)? Since in both a tableview and collectionview you are reusing the same cells again and again (with the same layout) so it is difficult to create a view with so many heterogeneous elements like in the picture above.
Use a table view and a bunch of different cell classes each with their unique design (XIB or Storyboard) and height.
Select the cell class and height depending on index path and let table view delegate methods return accordingly.
Very basic stuff actually.
You only reuse cell classes if you need to. In the Yelp example the Directions, Call, Explore the Menu and More Info cells may have used the same design because the layout seems to be identical, only the image and text differs.

TableView like Contact app with photo [duplicate]

This question already has an answer here:
TableView like the Contacts app in the iPhone
(1 answer)
Closed 9 years ago.
How can i make a tableview like the contacts app,
the main problem is how to place correctly the photoHolder like this :
I give you suggestion that actual UITableView should be Start at 'Telephone' and remain cell such like 'nome', 'Sobrenome' and 'Usuaroi' and also 'photo' taken BOX its all are create on custom UIView.
After Custom view is created then create your UITableView Wich Have groped style and it all customize by UILabel and UITextField.
Interesting.
Never tried such a thing.
If it is really a table ...
I'd try a custom cell for the first 3 cells of which I'd try to change the frame. (Move to the right and make it smaller. But code it in a flexible way. No constants. Use offsets from the right and left margin of the table view.
Then I'd try accessing the table view itself, which in the end is not much more than a subclass of UIScrollView and add a UIImageView as subview exactly there where the photo goes.
Give it a try and have fun ...
Another suggestion:
The first section of the grouped table, the one with the photograph to the left, is not the first section of the table. It is the table header view.
This table header view contains of an UIImage view and a UIcontrainer view. That UIContainer view has a table in it. That scroll view's property is set to not scrollable.
May not be the best idea but looking at the design, it coud work.
Just ... I am not sure how that top left table reponds to scrolling gestures. Touches (selections etc) should work fine.

Adding buttons to static table view/calling methods from tableview cells

Quite simply, I'm trying to add multiple buttons to the bottom of the static table view, much like in the address book app (below the contact's details for Send Message, Share Contact and Add to Favourites). However it just simply won't let me add three button in Storyboards unless I use a subview but then I can't quite get the colour to be the same as that of the iOS 6 background (and I've used the colour picker). What happens is that it'll simply add the button below the table view section and it takes up the entire width of the iPad's screen.
My other (and original) thought was to use the static table view cells to simply call methods. What I want to do here is add the building's details (like address, name etc) to the user's contacts app when they press the tableview/button - but I can't link it to any IBActions.
Using a button would be no problem, so if the first issue could be solved that'd be excellent.
If you use the solution with the subview, you can set the views backgroundcolor to [UIColor clearColor]

What is the alternative to static style cells in storyboard?

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.

Resources