Two views of one controller presenting the same data in different ways - possible using storyboard? - objective-c

I have a controller that will send a set of data to the view. This set of data must be viewable in two different ways (no, this is not about landscape/portrait), thus two different views. My question is, how do I create these two views, linked to one controller, using storyboard? I want to be able to see and edit both views without doing any ugly tricks.

In my experience it gets a bit messy when trying to deal with different "main" views in the context of one controller no matter what you do.
Basically you need to create another view right on top of your UIViewController's view in storyboard and make it hidden, connect its outlets to the controller and when a button that flips your presentation styles gets hit you need to either show or hide your second representation view like this:
- (void)btnAction:(id)sender {
self.secondView.hidden = !self.secondView.hidden;
}

Related

iOS 7 settings like DetailViewController

I have a simple project that was started from a Master/Detail template for iOS7.
I'd like to layout the detail view controller just like iOS settings. Do folks recommend using a table for that or just laying out the controls one by one?
Here is a screenshot of the effect I am looking for:
This is probably a matter of taste/opinion but I prefer tables for this kind of thing for these reasons:
You get all the nice features of tables right out of the box (efficient scrolling, cell reuse and delegate methods to handle where to push new view controllers on to the stack, etc...).
Flexible data model backed cell data. Your table view needs to be backed by some "settings" model object collection, obviously. That collection can be modified to include or exclude settings programmatically. Combine this with custom cells and you're off and rolling. This is really nice if your UI needs to change on the fly.
Code Reuse. If you have another set of "settings" you can use this data-backed table view approach and change only your data model. Doing this manually means you have a new view controller for every settings view. In your example picture, I'd bet my lunch that the 3 view controllers you see in that image are the same type of object.
The table's delegate methods are really helpful when segueing or pushing to new view controllers. Imagine having 10 settings that all took you to separate view controllers. You'd have to manually hook those transitions one by one, yuck.
Of course if you only have 1-2 settings that will never change, perhaps manual is the way to go. For my money, though, tables make sense because things like this always seem to change.

Using one storyboard definition for two view controllers

Is it possible to use one storyboard setup of a view controller with two view controllers?
Situation: I created one view controller's view in my storyboard. This one lets the user add a new data entry. Lets call it MyNewEntryViewController. This works fine. Now I need a way to edit my data entries. For that I'd just like to subclass my first view controller and adapt it where it needs to be. Lets call this one MyEditEntryViewController.
I would load MyNewEntryViewController using instantiateViewController… on my storyboard:
MyNewEntryViewController *newEntryViewController = [storyboard instantiateViewControllerWithIdentifier:#"NewEntryViewController"];
That works great.
What if I want to instantiate my new view controller now? Trying the obvious
MyEditEntryViewController *editEntryViewController = [storyboard instantiateViewControllerWithIdentifier:#"NewEntryViewController"];
results in an MyNewEntryViewController stored in my variable because that's what I had defined in that storyboard.
So, whats the best way to work with my storyboard definition and be able to use two different view controllers? How do you guys do this?
Thanks!
–f
No this is not possible. It is possible to do this with plain old xibs. You can then specify the name of the nib when you initWithNibNamed:bundle: the view controller.
However, I think it's worth taking a step back. Is it really a good idea to do this? Subclassing view controllers can get messy. View controllers are intended to be self contained units of functionality, which is at odds with subclassing. Unless a view controller is specifically designed to be subclassed then I would avoid doing so. I would suggest that you merge the two view controllers and override setEditing:animated:.

Using the same custom table-view multiple times in one window?

I have created a table view in a nib that I want to use twice in the same window. The table view has its own controller, and I want to connect various parts as outlets. I can do that in the tableview's nib by setting the file owner to the view controller. However, how can I then get this tableview into the parent window?
It looks as if I can't do it through the interface builder?
So I have begun by creating two instance variables in the window controller for the two controllers. I assume I have to do this programmatically? How do I set the locations of each view correctly? Are there any side-effects from doing this? I am doing the window layout for everything else within the interface builder itself. I just can't see this working, however.
I also tried adding in a couple of scrollviews in the window where the table views would go. I thought perhaps then I could hook the scrollview up as an outlet and add them this way. At least then everything would be laid out correctly. This also doesn't seem to work though.

Using a shared TableView for 3 of my tabs

I want to use the same TableView for 3 of my tabs instead of using 3 identical TableViews. I created three navigation controllers (one for each of the tabs) and linked them to the same Table View Controller But if I run the app with the storyboard like the picture below, it works for the first one of the sharing tabs, but for the other two I get a black screen where the tableView should be. So I want to know if it is even possible to make it work with this setup?
I'm trying this, so I don't have to make a litte change in the tableview 3 times.. The 3 tabs are populated with the same data too, just filtered differently, so just filter the array depending on which parent navigation controller would be simple I suppose.. But I need to know if this is a possible way of sharing view or not.
I would suggest a different approach. Just have three different table views. But since the question is not about being the right approach, I would say that the best way to do it is to do it by code, removing the tableview from the super view (The view controller's view) and moving it to a new view controller when the delegate from the tabbarcontroller is called. Keep in mind that you will also have to assign the delegate and datasource for each view controller.

Can you assign different buttons for different views using a split view controller?

I am creating a split view ipad app. I have four buttons in the master view which segue to four different views. However, when I am in certain views I don't need all of those buttons to display in the toolbar. So basically, is it possible to change the buttons for different views in a split view controller? any advice, tutorials, or source code would be sweet
Adding to what Lu Yuan said. You could put a pointer to the instance of the master view in your app delegate so that when one of your subviews load, it can get the master view instance. Then you can hide which ever master view buttons you want.