XCode Storyboard and UIViewController instantiation - ios

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.

Related

Creating component of UICollectionView/UICollectionViewController by using Xib and Implement it in UIViewController

I'm trying to develop a component of UICollectionView or UICollectionViewController which I can use multiple time in my current project and also can be used anywhere by simply copy-pasting whole folder.
Requirements:
- Create an Xib of either UICollectionView or UICollectionViewController (which one is easier).
- Embed that CollectionView xib in my UIViewController, In my that UIViewController there are some graphs and also some pics that I've to show(collection view is for that).
- Basically I want to send a JSON file and some parameter if needed to that component and make the collection view running within that View controller.
I'm facing a lot of problems embedding both of UICollectionView and UICollectionViewController so what should be the best way and proper approach to do it?
You could use a container view to embed a view controller inside another view controller.
This is from Apple documentation:
Container view controllers are a way to combine the content from
multiple view controllers into a single user interface

How to create a separate view in Storyboard to be included programmatically in UITableView?

I have a UIViewController with a UITableView that is fed with data from the local database. When the user first launches the app (after installing) the table view is empty and I display a UIView in the middle of the table view that contains a UIImage, a UILabel and a UIButton (a call to action).
The first version of this view I built programmatically, which was no good to me because every time I tweaked something I had to build the app again. Then I switched to the storyboard but had to drag a UIView to the middle of my tableView. It is working now but I don't like the way it is, I can't edit my table view cells without having to move the UIView out of the table view.
I'd like to have a way to build this view entirely separated from my tableView (or even from my view controller in question) and then reference it in the viewDidLoad call of my view controller.
Unfortunately Xcode does not allow us to drag views directly to the storyboard so I'm pretty lost here.
Please tell me if I haven't been clear enough. I appreciate any help you could give me.
UPDATE: It'd be particularly awesome to me if I could also create a custom Swift class for this view of mine and reference it in the storyboard. And then in my viewDidLoad I could simply instantiate my custom view.
Thanks in advance.
Create a XIB file in which you can drag a view (without a view controller).
In your code you can load the XIB using NSBundle.mainBundle().loadNibNamed("MyXibName", owner:self, options:nil).
In the XIB file you can give the UIView a custom class (like you can do with view controllers in storyboard).
You then of course have to retrieve the view from the array returned by loadNibNamed and cast it to your custom class.

UITableViewController in UINavigationController to represent tree structure of unknown depth

I am pretty new to iOS. I have some data that is essentially a tree structure which is fetched from an external database so its depth is not defined at compile time for the app. I would like to display this information using UITableViewControllers inside of a UINavigationController. At this stage, I have embedded a UITableViewController in a UINavigationController in my storyboard, and have written a subclass of UITableViewController to display the first level of the tree. How do I programmatically segue to a new instance of the subclass of UITableViewController that I have created while also creating references for prototype cells I have defined in the storyboard. Is it possible to set up this kind of structure in iOS with UITableViewControllers and a UINavigationController?
Any help would be much appreciated.
Thanks!
In your TableView delegate, put some code into the didSelectRowAtIndexPath: method to create a new instance of your tableViewController subclass. Either pass it whatever data it needs to populate its cells, or possibly use your top level TableView delegate/datasource as the delegate/datasource for every new instance (you will have to keep track of where in your data hierarchy). You can then use self.navigationController pushViewController:animated: to transition to the new tableViewController. If you use the same subclass at each level, the cellForRowAtIndexPath: method will use the same cell reuse identifier (unless you code otherwise), so your prototype cells should be used at every level.

UIStoryBoard - Same ViewController/Xib, different segue path

This is my scenario: I have an app with TabBar and NavigationController using storyboard. TabBar has item A and item B, both an identical UITableViewController and cells prototypes, it only fetch the info from different locations.
How can I identify from which UIStoryBoardSegue it came? Or there is a better way to do this (maybe duplicate Xib and UIViewController)?
Here a picture of my UIStoryBoard:
I was recently working on a project with the same structure and I added two tableviews. But i think it's possible to have one tableview with two different source views. You can try using a navigation controller and when you push to the table view the "back" button will bring you back to the origin.
Seems strange to have two Navigation Controllers pointing to the same Table View. Why don't you just copy the Table View in the Story Board and use the same class?

UITable view interface builder creation

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.

Resources