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

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]

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.

keyboard hides text boxes in static table view

Object C - iOS development. Hello all. I have a static table view with several text boxes to enter information. When I tap on a lower box, the keyboard hides the text box preventing entry of text. This app uses another static table view controller and when a lower text box is tapped, the view scrolls up allowing text to be entered, so it works fine. I must be missing a setting of some sort, but can't find it. Your help is greatly appreciated.
If you have a full screen table view controller by a subclass of UITableViewController then the keyboard interaction will be handled for you.
If you don't (you aren't using UITableViewController) then you need to do it yourself. Basically, you need to observe the keyboard notifications and use the keyboard frame they provide to you to change the table view frame so that it isn't below the keyboard.
See the docs for UIKeyboardDidShowNotification here. You might also like this project.

Table View Design Issue

My app design required a page that display 'user information' and i currently have this setup using a simple table view in a View controller. Now, the tricky thing is I need to be able to provide functionality to the user to be able to edit these on the same same screen. So essentially when the user taps on a row in the table view, I want that little flashing text line at the end of the current text in the row so the user can edit what's currently present and I also want a save button to apear on the top when a user has started editing. The tricky part is, not all fields in my table view will be editable. So, I need certain fields to be editable and have the save button appear and certain fields not.
Can you tell me how would I go about modifying my existing design to implement this functionality? I would appreciate some code if you think you can show me how exactly I would go about doing things.
You would probably want to make some custom UITableViewCells. You can fill a tableview with all sorts of different cells which are different sizes and looks different, all at the same time. I would suggest a custom UITableViewCell which will hold a UITextField as one of the subviews. On the cells which you don't want user interaction with the textfield, either make a new custom cell that uses a UILabel or just do textfield.userInteractionEnabled = NO. Look up some custom uitableviewCell tutorials to get you started and then use the approach that I suggested for your problem.

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