iOS UITableview similar to contacts app - ios

I am trying to replicate the contacts application in iOS, using two table views in the "New contacts" view. I am trying to scroll up the tableview when the keyboard covers the content. Each cell contains a textfield, I have to enter into that some details. I have used two table views, one is placed as header view over the other. I am not getting the code to scroll up the tables... Any help will be highly appreciated. Thanks in advance

If you want the 2 tableviews scroll together you have to use only one main tableview, I mean, you have a main tableview with all the content, and then cells with the textfields.
The cell with the photo, name, surname and enterprise (I'm not sure if they are the correct names because I have it in spanish), contains a imageview for the photo and a tableview with 3 cells, one for the name, other for surname and other for enterprise.

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 does AirBnb create a collection view with different cells?

I noticed in the Airbnb app when you click on a specific cell on the home screen, they have a complex collection view displaying various items in different looking collection view cells. I have attached 4 pics below:
In those pictures you have different sections like About your host, Availability, Reviews, Group size up to 2 guests, Guest requirement, Contact Host, etc. How does one go about organizing a view like this?
Is this just a bunch of different cells in a TableView or CollectionView? Since every single item I click on the home screen has a very similar layout with the exact same sections. Or are these just views placed on a scrollview?
It's probably a UITableView or UICollectionView with a set of different cells. So their cellForRowAtIndexPath: cellForItemAtIndexPath: functions would return a different cell class for each different section.
They'll have an AboutYourHostCell class, an AvailabilityCell class, a ReviewsCell class, etc.
It would be possible to do this by adding Views into a UIScrollView, but it would be a lot of work, and you'd lose some nice behaviour that UITableView or UICollectionView provides - like highlighting cells when you press and hold, and animating changes.

Issue with programmatically added buttons

I have a cell in the UITableView. The cell has a UITableViewCell class. In this class I programmatically add few buttons.
Note: the cell is located in the very end of the table view.
Issue:
If I'm using simulator iphone 5 > the buttons will be shown.
But if I'm using simulator iphone 6+ > the buttons will NOT be shown.
Note: when i'm opening it on iphone 5 I need to scroll to see that particular cell. on iphone 6+ i don't need to scroll there, the cell is visible right away.
So I think the issue is somewhere here. May be with the place where I do my 'buttons adding'.
Where should I call the method that sets up the buttons?
Or how can I solve this problem?
TL;DR: If you have different cell types in your table view, you should make sure they have different identifiers.
Explanation:
Table cells are re-used within the UITableView and when the table is first being displayed it won't have any re-usable cells yet. It gets the cells to display by calling on its data source through the UITableViewDataSource protocol.
The thing providing the cells will first ask the table view if it has any re-usable cells (of a particular type), before creating a new one. The way it determines the particular type is from the reuseIdentifier in the table cell.
So, if you have two different classes of table cell, but they share the same reuseIdentifier you will sometimes get one class and sometimes the other - if you get the one without buttons when you're expecting the buttons then this will be a problem!
The answer is to make sure your different cell types have a unique reuseIdentifier.

expandable cells table view best practice for ios

For the iOS we are not been provided any expandable list view as a component. so to use the expandable list we are having 2 basic options:
Option-1: Table header as the main view and then clicking on it open cells under that header.
Option-2: Cell as the main view and add more cell below as if its sub cells when clicking on any of the cell.
And more than this 2 different developer uses different logic. so Can we know that which would be the best practice to use expandable/ collapsable Table view in iPhone/iPad application.
Thanks in advance. This could be consider as a knowledge sharing or better coding practice related question.
There are a million ways you could do this.
In the past I have created a custom "stretching" cell that would stretch its own size to show items that were hidden. This could be a way of doing it.
What you would need to do is have a cell that when clicked, opens up (revealing a new cell hidden underneath it). You could also have it seem as if there is another cell being shown below the clicked index, but in reality you are only adding a new cell at cell_index_clicked + 1.
Hope this helps you think it out.
Use iOS 8 auto layout ..........

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