UITable view interface builder creation - ios

I am building an app using storyboard. I have added a table view to my view controller, chose static cells, and custom, insertea a title and some pictures. I have also linked each row to a view controller, with modal segue. But I want to be able to add, delete, and reorder the rows. So I added the codes. The only thing is that I can not connect the table view to the codes. If I connect the data source, and run the project I see just an empty table view. So, is there a way to create the table view using interface builder, and just a few codes? otherwise if there are to much codes everything gets messed up.

Connect delegate and datasource to ViewController icon in your Storyboard. Then add UITableviewdelegate and UITableviewdatasource in view controller code. When you connect and do this, then tableview will search its delegate and datasource methods in your code and you will get the output which you expect.

If you want to add, delete and reorder the rows, you can't use static layouts, because those operations make the table view not static!
You will have to implement it using datasource methods and dynamic prototypes. It won't be too difficult. You can still build each type of cell in the storyboard, you can have multiple prototypes with different reuse identifiers.

Related

Cells not appearing when linking table view controller to table view file

Very new to iOS dev so a little help would be greatly appreciated !
Created a table view controller with static cells in it. If no swift file is linked to it, I can see the cells when building the app.
However, if I link a table view controller to it (which I believe I should?), I don't see the cells anymore. Why is that?
Thanks !
There are several things you have to keep in mind when using Table View.
First, you have to make sure you link the table view to your file by control dragging it from the main.storyboard to your view controller.
Second, you must make sure that the cell has an identifier. Make sure you select the cell and not the table and set the identifier to a certain name (for simple projects, we generally just use the identifier "cell")
Third, you have to make sure that the datasource (and usually the delegate) is set to the view controller.
There are two ways of doing that, first, you can drag the table view to the View Controller icon (I believe it is the yellow one, but one of those on the top of your iOS screen storyboard), and select datasource and delegate. The second way is after you have referenced your table view to your view controller file, in the viewDidLoad method, set the table view's delegate and datasource to self. For instance, if your table view is named as tableView, the code should look something like
tableView.delegate = self
tableView.dataSource = self
Forth, make sure you include the following methods in your class. The numberOfRows, cellForRowAtIndexPath, and for numberOfSections, just return 1.
If everything still doesn't work, you can share us the code, maybe there are some other potential problems I forgot.

How to create a custom header view for a table view section using outlets and IB

I would like to make a custom header view for a table view section in Xamarin.IOS with interface builder. However, I dont want this view to have a static content, instead I would like to create outlets, so I can modify the element's value contained in the view.
I have done custom table view cells before with interface builder (piece of cake), so the question is: is there any way to accomplish this on a section header too?
This is what I want to do:
PD: I'm using monotouch.dialog, and this controller is a DialogViewController
I recommend you to use a UIViewController instead a UITableViewController and put the first part of your design (the user information and the buttons) in a UIView and the restrings section in a UITableView.
It's a better solution than implementing a UITableViewController with multiple headers.
let me know if it works for you.

how to implement multiple segues using dynamic cells in Xcode?

i have a table view with dynamic prototype cells divided into 2 different sections named "Forums" and "Threads". When i click on a tableview cell from the Forums section, i want to transit to the same page with a different data to display while if i click a cell from the Threads section, it should open a different scene. In short, two different types of transition segues from 2 different tableview sections)
Can anyone please help me with this?
Make sure the table view controller is embedded in a navigation controller.
Hook up two push segues to the table view controller (not to the cells).
Give those segues appropriate identifiers in the storyboard using the attributes inspector tab on each segue.
In -tableView didSelectRowAtIndexPath: add an if statement to detect which section the row tapped was in.
In the branches of the if statement, call -performSegueWithIdentifier on your controller using the identifier of the appropriate segue .
If you need to set up anything in the view controller you're seguing to from the table view, override prepareForSegue: sender: in the table view controller.
Very helpful, it worked for me, but I had to used BOTH didSelectRowAtIndexPath AND prepareForSegue, while I was reading in other posts that this is not very good.
I read that we need to use only the prepareForSegue if we need to set up any stuff...
Do you think that I should continue with both of them?
Thanks!

iOS: creating a tab bar application with embedded table views using Interface Builder

I am trying to do something very basic. I want a tab bar application where some of the tabs contain table views. I am working with Interface Builder.
I can create a tab bar app starting from an empty app using code found in Beginning iPhone 6 Development. That's easy. I create the app, create an empty nib, then drag a tab bar controller into the empty nib. Set up the hookups, the root controller, and load the nib from the App Delegate. Works fine. I can then create more nibs and assign each nib to each tab item. If I add a label to each nib, it's fine.
I can create a table view app. Start with a view app, go to my main nib, drag in a table view, implement the methods inside the class, hook everything up, it's fine.
But when I combine those two, it doesn't work. Specifically, get the tab app working. From one of the views (separate nib), delete the label and add a table view instead.
I do all the same things as I do in the simple version. I cut and paste code. But when I run it, I get messages about invalid selector being sent (numberOfRowsInSection).
So... clearly I have to do it differently.
Comments?
You need to implement the tableview delegate methods. There are specific methods that drive the data and delegate of a tableview. Anytime the tableview loads your app will be looking for these methods. One of them being (numberOfRowsInSection). Make sure you have hooked up your delegate and datasource in IB (by right clicking the tableview and using the drag commands to select File's Owner). Then you have to implement the appropriate methods to setup a tableview.
These methods can be found on the Apple Doc site for configuring a tableview linked below:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html

Different Segues from Different UITableViewCells?

This appears to be a storyboard editor issue because it's easy to do in code.
I have a UITableView with two different prototype cells. They have reuse identifiers, different accessories. I want selecting one type to trigger a segue to another view controller, and selecting the other to go to a different view controller. But as soon as I create the second segue in the storyboard editor, the first one is replaced. Even if I have named it.
It seems this should be a common enough scenario, I should be able to have multiple segues, and differentiate them in prepareForSegue.
I need to note, this is easy to do in the didSelectRowAtIndexPath for the view controller's table view delegate, but there I have to explicitly load the template from the storyboard (unless I use a generic and don't need a nib).
Has anyone been able to get this to work in the storyboard editor?
The only way I could think of to do this with how things currently work is by using two different types of prototype cells. (two separate classes) and assigning each different segue to each different subclassed prototype cell.

Resources