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

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.

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!

Creating a menu in iOS

I'm currently creating an update of my iOS application and I'm a bit stuck. I've tried to googling around but cannot find a decent answer on this.
I've a menu which links to different views. And I'm not really sure if I've done it the best method.
I've created a view, and added the links into a stack view. Should I considering changing it all to a tableview? or a collection view? Or maybe there's another way?
The current look:
Should I change this to a tableview? collection view? or something else? Or just let it stay as it is?
If the number of items in your menu changes at runtime and is large, you should use a table view, because a table view is good for efficiently displaying a screen's worth of items from a large list of items.
If the contents of your menu is small (under maybe two screenfuls of items) and fixed at compile time and you are using a storyboard, then you could use a table view with static cells, if you can make it look the way you want.
If the contents of your menu is small, then you can use a stack view (inside a scroll view) if that is easier for you. There is no particular advantage to using a table view over a stack view to display a small amount of content, unless you need other features of the table view (like the ability to select/deselect rows).
Based on the screen shot you posted, I'd either use a table view with static cells (since the screen shot is from a storyboard) or a stack view, depending on whether I can get the appearance I want from a table view. If, as in the screen shot, the buttons must be centered vertically, I'd use a stack view, because it's easier to vertically center the content with a stack view.
Look, the fact of have many itens on your screen is clear on the mobile applications, to make it easy, we have collecions view like UITableView and UICollectionView. On the UITableView's case, this implements the scrolling and have methods do handle the operations' list, you can see the documentation to check these methods: https://developer.apple.com/documentation/uikit/uitableview.
Main reasons to use UITableView
Implements scroll behavior.
Independent of size screen you can access all itens.
Easy to detect interactions like tap on cell.
Easy to make changes, like insert and remove content.
The UITableView exists precisely to solve problems like you has.

Is there any way to make a custom table view cell look like a button in Xcode 6+?

I'm trying to create a Table View Cell array and have the name displayed in each table. The tables will look like what you see on the home screen of the Evernote app (shortcut, tags, places, notebooks etc.) and each one will access the next screen when tapped. How do I go about doing this? Novice app developer.
This is an image of the result I'm trying to get.
That is a basic cell with transparent background and other views (and images, layers, etc.) added as subviews.
For the other things I suggest to study how UITableView works and how to push a UIViewController using a UINavigationController.
In general you should study iOS and Objective-C from zero.

drill down UITableView using storyboard in iOS program

I'm trying to develop an iOS app that has drill down UITable View. I got a drill down table view tutorial, but the number of UITableViews is static. What I need is a dynamic one. My requirement is simple. I need to access an FTP Server and get the directory hierarchy (I guess I need to store it in NSDictionary or in an xml file) and display the content in the UITableView. If it is a text file, I need to display it in some view, otherwise I need to display the selected folder's content in the same UITableView, and it goes on till the bottom of the directory hierarchy.
I need to use the storyboard.
I've had to make a something very similar to what your talking about in a previous application I worked on.
In that I created table views inside of table view cells with a button at the top to expand and collapse the view using the cell height.
This worked pretty well but since then I've found the best way to simply programmatically add ui elements to either your table view cells or view.
In both cases I created a management system using parent child architecture to hold your information.
I hope this puts you in the right direction :)

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