Using Storyboard, UISplitViewController and multiple detail views (MultipleDetailViews with storyboard) - ios5

All,
It's not this: Science At Hand - Adventures in UISplitViewController. That really goes from the UITabBarController rather than the cells in the Master.
Let's say I want to create a SplitViewController. On the left side I have different types of cells in the same list (It's not going on Apple Store, so I don't care if it's Apple iOk or not). For each of the different cell types I want to have a different DetailView controller. Cell Type A shows DetailView A, Cell Type B shows DetailView B.
How do I update the SplitViewController subviews to shift detailviews?
Can I just put the navigation controller under the detail and then add viewControllers to that? Using the get based on seque name or get view from storyboard?
Some other, really obvious way that I'm just missing.
For bonus points, I would like a way to detect that I'm leaving one detailview (for saving) and moving to a different detailview (A different cell type button was pressed)

It turns out it was simple.
If you do the obvious (who would have thought?) it works just fine. I created my different cellviews. Each cell view has details link that I just linked to a series of view controllers. I just had to change the seque so that it was a replace and it put the view into the detail view.

I'm make this sample in GitHub
https://github.com/AlfonsoMoreno/MultipleDetailView
MasterViewController is UITableViewController
FirstDetailViewController is UIViewController
SecondDetailViewController is UITableViewController
You can add more views!!!
Please watch MultipleDetailViewManager class!!!

Related

Objective - C How to manage multiple views with View Controller iphone

I am new in developing iOS apps. I am trying to develop a multiple views app. My doubt is how to manage a multiple views app with View Controller, I mean, I do not want to use Navigation Controller nor Tab Controller.
My idea is to show a first View to choose the language, and after this, I want to show some different profiles in a table view. When you choose the profile, you get into a menu where you have some different functionalities (Once in this menu, I might use Navigation Controller).
My problem is that I don't know how to manage these two first views. I don't know if I have to declare them in the appDelegate, or if I can do it nesting one to other, I mean, I do the first view, and when I pressed the button, I declare the new view. Once in the new view, when I pressed a row in the table view, I make the another view.
I know it is a little bit confusing, so I hope you could understand it quite well.
EDIT:
I want to clarify that I am not using storyboards. My main doubt is what to do with all de view controllers, Do I have to declare all of them in the appDelegate? or Can I declare each view in every controller?
If you are using storyboards, you can use Segue's to navigate between the views, so you would show your first view, then you could tie a button to the next view (by control dragging in storyboard). If you want to transition programmatically you can use the performSegueWithIdentifier method. You could use the same approach to get from your tableViewController to your next viewController by using the performSegueWithIdentifier method from within the tableViewController's didSelectRowAtIndexPath delegate method (i.e. when a user taps a cell).
That should get you started. Good luck!
EDIT:
You really should be using storyboards. It's the way to do things these days. If you refuse, then the best approach is to create a container view controller that manages your "children" view controllers. You can find information on doing this, as well as the methods needed to present/remove child view controllers here:
Custom Container View Controllers
You can use navigation controller with "hidden" property.
self.navController.navigationBarHidden = YES;
If you want to have two different views and transition between them, you will want to use UIViewControllers presented modally. Here is Apple's Guide to this.

Setting up Transitions/Segues from different elements of a Table View using Storyboards

I believe my question is relatively basic but I still haven't found something that directly answers it. I'm trying to learn Objective C and iOS Programming using Storyboards and am in the process of building my first app now. The way I have it set up right now is, I have a Navigation Controller that goes to a Table View controller (controller A). I'm passing an array to my table view and I have the disclosure indicators on the different elements in my array. I also have a second different view controller (controller B) with a table view in it. I want different elements of controller A to transition to different views/controllers etc. I'm familiar with the concept of segues and the prepareForsegue method however, I dont need prepareforsegue here since I'm not really passing anything to the next screen. I just want to be able to click different elements of my Table View in controller A to bring me different views (i.e like controller B and other views that I plan to build). Is there something I'm not seeing or do I need to fundamentally change my design?
Perhaps you're thinking of creating different prototyped cells?
Here's how I understand your question:
I have two (or more) different kinds of cells where I know the view to which they would transition beforehand (when your table queries the delegate).
I would like those cells to go to different controllers rather than the same controller.
If this is right, check it out:
Create a new UITableViewCell in the table by dragging from your kit
of UI objects.
Give each cell a reuse Identifier
Control+Click and drag to your target view controller
You'll get a popup asking what type of segue and what UI object triggers the segue
Then you'll see two segue indicators leaving your UITableViewController
Finally, make sure you dequeue the right type of cell:
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:#"CellReuseIDA"];
return cell;

ios, code-reuse issue, reuse viewController?

I have a view controller(A) which shows a list of items download from server.
I have another view controller(B) with segmented control.
When second index of segmentedControl is selected, the view controller(B) shows a list of items in the same format as in the controller(A).
When first index of segmentedControl is selected, the view controller(B) shows the items in different format.
I want A and B share a code for the common stuff.
I first thought ok I could move all the view-related code to "common_view class" and use the view class from both controllers.
But, it turns out that there are codes which are not related to view(such as downloading stuff from server, which is controller-part of mvc pattern).
Now I'm perplexed, "is it a good idea to share a controller-part code? is it even possible?"
I could factor out a common code into a commonViewController, and instantiate it from controller(A) and controller(B), and add commonViewController.view as a subview.
But is this really desirable? or do you suggest any better way to do this?
Yes definitely..you can.Use two NIBS in this case.The first NIB wil be used by ViewController A and first segment of ViewController B.On selection of second segment in ViewController B addSubView of viewControllerA which initsWithSecondNiB name.Once you have added them ,control their visibility by show/hide when toggling between between the two segments of viewcontrollerB

iOS5 - how to use storyboard to transit from UITableViewController to another ViewController

Using Storyboard I want to transition from UITableViewController to another ViewController on the click of Detail Disclosure button. I created a proper segue, but the transition does not happen when I run the application. Creating a segue from UIButton to a ViewController works properly. I tried embedding Navigation Controller in UITableViewController, it did not help.
Look forward to somebody helping me with this, as I have already spent four days on it.
Thanks!
Here's the most complete example I have found. Most have fallen short by not providing an example of how to go from the list of records to the detail of the selected records.
http://developer.apple.com/library/ios/#samplecode/SimpleDrillDown/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007416-Intro-DontLinkElementID_2
and here's the link to part 2 of the above tutorial:
http://www.raywenderlich.com/5191/beginning-storyboards-in-ios-5-part-2
It should work without any code on your side
Ctrl click the prototype cell (table cell) and drag it to connect with the detail view. This will pop up a segue window. I chose Push since I have a navigation controller - but you can use Modal as well.
Note the segue name should show "Segue from UITableViewCell to ).
I've put in the disclosure icon on the Table cell as well.

NavigationController with search, map and table: how to

Since I am a newbie in iPhone development, I need some advice on how to structure my xib file in order to get the following (essentially, it should be very similar to Google Places app).
I need a NavigationController with:
Map with search functionality.
TableView with search functionality (ideally, the search should be shared between map and TableView).
One view to show details of a selected item, whatever the source view is (map or table).
Map view should have a button to show listing view, and viceversa.
My doubt is, what do I have to nest where? I have a NavigationController with its View Controller set to another class with its own xib, but I don't know how to go on.
Should I create a View with a search bar and another SubView to switch between Map and Table? Or is it better to have two full views each one with its own search bar?
EDIT 1
Finally I have decided to implement the following structure:
- TabBarController
- LugaresNavController (UINavigationController)
- LugaresViewController (UIViewController)
- UISearch
- SubView (UIView)
- MapViewController (UIViewController)
- TableViewController (UITableViewController)
MapViewController and TableViewController have their own xib files. What I want is to have the ability to switch between them into SubView, but I am not able to do it.
I have assigned MapViewController and TableViewController file's owner to their respective class in the xib files, and also have specified which xib to load at the attributes of their representation in the xib corresponding to LugaresViewController, which is their parent.
When I run the application, all I can see is the TabBar with the NavBar and the UISearch. The frame where SubView should render either the map or the table is showing blank...
What am I doing wrong here?
Your fundamental problem is that you are getting your different parent-child hierarchies confused.
To recap: MVC is Model, View and Controller.
iOS has TWO different parent-child hierarchies: One for the controllers and one for the views.
The following are part of the controller parent-child hierarchy:
- TabBarController
- LugaresNavController (UINavigationController)
- LugaresViewController (UIViewController)
This means that LugaresViewController.parentViewController should be LugaresNavController and so on.
However the following doesn't make any sense:
- SubView (UIView)
- MapViewController (UIViewController)
- TableViewController (UITableViewController)
Views can have subviews but views can't have subviewcontrollers,
Are you doing the following?
- SubView (UIView)
- MapViewController.view (UIViewController s view is a subview of Subview)
- TableViewController.view (UITableViewController s view is a subview of Subview)
This is a view parent-child hierarchy. This means that:
SubView has two subviews (MapViewController.view and TableViewController.view)
MapViewController.parentViewController is nil.
MapViewController.navigationController is nil.
you can use view transtions to switch between MapViewController.view & TableViewController.view but not viewController transitions (such as presentModal... or push or pop ViewController...).
If this is what you want, then you just have to make sure that you do:
[SubView addSubview: MapViewController.view];
[SubView addSubview: TableViewController.view];
Incidentally, SubView is a terrible name. Usually we call those containerView or something like that.
subview is such an important concept you want to be able to diffrentiate the concept of a subview from the instance of that view. It's like naming your child "Kid" or your dog "Puppy".
your App is similar to mine, what I've done:
- TabBarController
- TableView
- SearchBar
- DetailButton ----\
- MapView \____ push ModalViewController
- SearchBar /
- DetailButton ----/
now if someone pushes a button in the table view or map view I'm opening the same View but pass other information to initialize it. btw. what is a LugaresViewController?
First try only adding a TableView and a MapView in each tab and look if the nib-binding works well. If not, you're missing something, load nib named or class type. Afterwards you can add the SearchBarController's and provide functionality for that.
First of all, I can't really say I agree with your tabbar application. I think a navigation application might work better for this idea. The first view would then have the navigationbar automatically added, with below the UISearchbar, a window, and a normal tabbar.
The UIWindow should contain a subview. That would be either the table, or the map. When you first load the application, and show, say, the table, you'd do:
[window addSubview:tableViewController];
When you switch to the mapview, you'd do something like:
[tableViewController removeFromSuperview];
[window addSubview:mapViewController];
So, for switching views, that's where the UITabBar comes into play. Make sure the tabbar has two segments. Hook up an IBAction to that, which looks a bit like:
-(IBAction)segmentedControlIndexChanged {
switch (segmentedControl.selectedSegmentIndex} {
case 0:
<call function for removing mapview and adding tableview>
case 1:
<call function for removing tableview and adding mapview>
default:
break;
}
}
Last but definately not least, which might be the answer to your edit: make sure you've connected all the connectors in Interface Builder (or, if your using XCode 4, just the .xib-file), from the .xib to the File Owner's.
EDIT: Ofcourse, the detail-view for the items pressed on the table/map is pushed in the navigationItem, so the back-button is automatically created and functional in your detailview.
Good luck!