I have a UITableViewController subclass in a Storyboard which loads it's cells from a UITableViewCell defined in a XIB file (this is done so that a custom cell can be re-used across a deep hierarchy of table view controllers).
I need to define the segue from this table view controller to the next table view controller. Normally you would do this by control dragging from the cell of the source to the view controller of the destination. But since there are no prototype cells in the source table view controller, there is no way to connect the segue.
Do I have to resort to implementing -tableView:didSelectRowAtIndexPath: in my table view controller and triggering a manual segue? Or is there a better way?
Yes, present the new UIViewController from -tableView:didSelectRowAtIndexPath:. Since you don't have a prototype cell, you have nothing to link the segue with. Just -presentViewController:animated:.
Related
I started to develop an app that use two view controllers (VCs). For each VCs I use a uitableview that use the same uitableviewcell. My ask is if exist a same queue between uitableview where to use a uitableviewcell between two view controllers or if i should create a custom queue where i can to reuse the contentview of uitableviewcell
More graph
VC1 - UITableView1 -> UITableViewCell1
VC2 - UITableView2 -> UITableViewCell1
I would like to reuse the UITableViewCell1 in both tables and decrease the use of memory.
pd: the navigation between these vcs is with a uinavigationcontroller.
Thx
Yes. You can do it by creating Custom Table View Cell and Use it in all table views.
I'd added solution for the same kind of issue on Collection View.
You just refer the same for your Tableview. You just repeat the same with Tableview cell.
Common Collection View Cell in all collection Views
Hope it helps.
I have the following situation:
There's a table view controller that displays all font family names, and it's inside a storyboard
Inside the UITableViewController in the storyboard there's a cell with identifier "FamilyName" that has also a disclosure indicator linked to a segue
I added a UISearchController that should filter the results of the previous table view controller
Inside the table view controller that acts as results updater I registered the same reuse identifier:
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "FamilyName")
And I'm calling dequeueReusableCellWithIdentifier:forIndexPath:, but I get a different UITableViewCell. I'd like to get the same cell that is in the storyboard inside the other table view controller, so that it's already linked to a segue.
Reuse your tableView. Don't make a new one just change the data source. This should work as intended. Just modify the data source and update the table.
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "FamilyName")
That means: Do not use the storyboard to get the cell. So you can hardly be surprised when the cell doesn't come from the storyboard: you said not to. The only way to get a cell from a storyboard is for the table view to register no class or nib for this cell reuse identifier.
I have a group of collaborating controls in a cell prototype. I found that I wanted to reuse this same collaborating group outside of the table, in another view controller.
So I made a new UIViewController in my storyboard, moved all of the controls there and moved the interaction behavior from my UITableViewCell subclass to the new one. Now I just need to put a container view in the prototype cell in storyboard and hookup the embed segue. Easy enough.
What I don't know how to do though, is where the new sub view controller (my new subclass) will be instantiated, and how I can refer to it from cell subclass code? I need to pass some information from the cell's properties down to the embedded view controller. I can create an outlet for the container view in my cell, but that's for the view, not the embedded view controller.
When you embed a view controller inside another view controller, the container viewController's prepareForSegue: method is called - here you can keep a reference to the segue.destinationViewController.
And therein lies the problem - prepareForSegue: isn't a UITableViewCell method, so there's would be no way to capture the child view controller.
Of course, as you've discovered - you get a compile error in any case!
I am new to objective C. I have a small app where I have used a UITableviewcontroller(TVC). I need to add four elements.,label and button above TVC and a label and button below TVC. But it is allowing only to add 2 elements., one above TVC and other below TVC. Also added element is occupying the entire width of screen. Can I overcome this restriction???
Customize the table view cell – instead of using the default style of table view cell.
this link is helpful you with sample project
http://www.appcoda.com/customize-table-view-cells-for-uitableview/
These two are tableview properties.
tableHeaderView
tableFooterView
By using the above properties you can show your own custom view on top / bottom of table view.
sample code
[self.tableView setTableHeaderView:yourHeaderView];
[self.tableView setTableFooterView:yourFooterView];
Write this code in viewDidLoad.
UITableViewController is kind of a screwed up class, in my opinion. A UITableViewController can only manage a table view, and nothing else. If you want a more complex layout where you have a table view on part of the screen, and then other view objects elsewhere, you can't do that with a UITableViewController.
However, with iOS 6 and later, there is a pretty easy solution.
You can embed a UITableViewController as a child view controller of another view controller.
What you do is to create a parent view controller with everything you need. Then you create a container view on your parent view controller and size it to contain your table view. Then you create a separate scene in your storyboard that defines a table view controller. Finally, you control-drag from your container view to your UITableViewController, and create an embed segue.
I have a project on github that demonstrates this technique:
Demo project using UITableViewControllers as child view controllers
Good afternoon,
I have a storyboard configured but I have difficulty with one aspect.
I am using a UITableView to recreate a directory structure i.e. folder>subfolder>files. The structure is going to be different for every user and the structure is supplied via a API. I currently have a UITableViewController within the storyboard.
How can I recreate this in the storyboard?
Currently I am just recreating another instance of the UITableViewController class and pushing it on to the UINavigationController but I of course lose all of the assigned segues.
Thanks
I'd expect one scene to represent the folder hierarchy. It would be a single UITableViewController with a table with 2 prototype table view cells. One table view cell would be for folders, the other for files. The table cell for the folders would have a push segue leading back in a loop to the table view controller. The file segue would lead to what ever scene you uses for files.
You can to use the table view data source and delegate methods to drive the table view and fill it with instances of your prototype cells.