Combine TabBar and SplitView
Example iOS project for iPad using both TabBar and the SplitView Controller.
Steps to create the project:
- Create project using the SplitViewController project template
- Create project using the TabBar project template
- Copy the RootViewController.* and DetailedViewController.* files from the SplitViewController project into the TabBar project
- I renamed the DetailedViewController.* files into ThirdViewController.*
- Open the MainWindow.xib of the TabBar project and add the third tab, the connection to the ThirdViewController will be handled in the code
- Apply the necessary changes to the SplitViewController application delegate files (see the example project)
- Add the makeSplitViewController method to initialize and connect the SplitViewController to the third tab
- Add the methods to handle showing and hiding the SplitViewController button in the navigation bar. These methods are called at several places e.g. when the TabBar is clicked, for the SplitViewController the orientation is checked and if necessary the button is hidden/shown
Now build and run the project
Updated May 5th, 2011: The example project is based on the article written by Mark Zangfound found on the iPhone Dev SDK forum. In addition I used some stuff from Greg Combs to handle rotation correctly. This code example is provided as the forum provides no sample and the discussion could confuse some programmers. I think an example tells a lot more and can be studied.
Download the example for TabBarWithSplitView testend with XCODE 4.3 here…
Tags: Code, Download, Example, iOS, iPad, ObjC, SplitView, TabBar
This entry was posted on Wednesday, March 23rd, 2011 at 8:37 PM and is filed under iOS. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
August 23rd, 2011 at 8:05 PM
Thanks for this but I couldnt get working. Im using xcode 4. this also is with this
BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch.
[self makeSplitViewController];
// Set the tab bar controller as the window’s root view controller and display.
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
Pressing Third tab. My app closes. Havent arrived with split view
August 31st, 2011 at 5:59 PM
Just checkend the project with XCODE 4.3. I needed to accept some automatic updates for XCODE 4.3, but I haven’t changed the actual code.
I have been able to run the project successfully using the iPad simulator.
September 6th, 2011 at 8:08 AM
simply great.. I was looking if this was possible andi it runs like a charm.
kudos!!
pash
September 13th, 2011 at 2:57 PM
Hello, thank for this article very helpfull ! Is it ok With the validation by Apple ? I souls like to use it for one of my app ! Cheers
September 14th, 2011 at 4:54 PM
Hi,
Glad to be of help…I know others are working with the code and are telling me Apple allows the code, haven’t used it myself for appstore..
I don’t think the code should give problems, but you never know with Apple.
Best regards, Bart
September 16th, 2011 at 8:45 AM
hi..
did some testing and it fails..here’s wat I did – run in simulator..go to tab 3 and select any row in split view.
Then select some other tab – say tab 1. Rotate screen to potrait mode while on tab 1. Then return to tab 3. The program breaks.
THis is the line where it breaks:
(void)addBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc
Any ideas?
thx
pash
September 20th, 2011 at 8:51 PM
Great!
How I should do to add another split view into this project?
Thanks!!!!
September 21st, 2011 at 4:35 PM
That needs a bit of investigation, when I have time (so much to do) I will look into it…
September 21st, 2011 at 8:05 PM
Good work, but a little bug in the project. To reproduce the bug, do as following:
1) start project in the portrait mode;
2) click on split tab;
3) return to the first tab;
4) rotate to the landscape;
5) go to the second tab;
6) rotate to the portrait mode;
7) go to the split tab and … application frozen.
It’s possible to make the same project in Xcode 4.2 beta 7 IOS5 using storyboard. It’s available on apple forum IOS5.
September 21st, 2011 at 8:42 PM
Ok, I think you found the bug mentioned by others, not sure when I get to it…
I am working on an update of an app for the AppStore, that has priority for me at this time.
As far as the request for XCODE 4.2 beta 7 and Storyboard. I have been to the WWDC and know about the stuff, but have no hands-on experience yet. So much too try and experiment with and so little spare time…So that will have to wait for now
September 22nd, 2011 at 11:30 AM
Bart, thanks for a quick answer. I guess you fixed the bug and reminded to you about it.
I like the beta 7 and iOS 5 which gives more possibility for designers.
October 18th, 2011 at 1:05 PM
Hi
I got the same problem that grey has.
I had to comment out most of EnhancedSplitViewController.m code to get the project work without locking, so…what EnhancedSplitViewController.m is needed for if the app works 100% without it ?
Also I’ve noticed that the splitview is rotate every time I rotate another view…is this correct ?
Ciao
Roberto
October 21st, 2011 at 10:37 AM
If you rotate the device I think you would expect all views to be rotated, not just the one you’re using at that time. So yes, it’s the correct that all views are rotated after rotating the device.
I haven’t figured out the problem, as I am working on an update of another app I don’t have a lot of time to dive into this thing right away. Probably needs some debugging, it’s a puzzle…Maybe it will prove to be simple, but I have too little time and too much to learn (iCloud and other stuff)…If I find something I will let you know, please try to look into the item yourself, maybe a fresh look helps
October 24th, 2011 at 4:26 AM
This template has taught me so much in a very short amount of time. If you had a ‘donate’ button I’d be all over it.
I’m just barely learning Xcode. I’m trying to convince me work to assist in my training in Objective C. So I’m trying to show them what we could do. I’m flying out there to show them a sample tomorrow.
As I said, I’m learning a lot, but I’m stuck on a few points. I’d love any advice if you have a second. They’re probably pretty dumb questions but that’s just where I am at currently.
1. I can not figure out how to edit the style of the Root navbar. I want to turn change it to the opaque black but it must be one of those things that it’s SO easy that no one ever posts the code online because I can’t find anything. Everyone just assumes that any app is going to have a ‘storyboard’.
2. How difficult would it be for me to create a split view page, like on page 3, on page 2? Couldn’t I just take another split view app and drag the .h and .m files over. Rework the IB and relink/recode? For me that’s not exactly the simplest thing but isn’t that the idea? Or is there a better way?
3. When I start the app and click the 3rd button I now enter the detail but it doesn’t default to my first item. It defaults to an empty page. Why would it do that? Is there a bit of code I can tweak to default right back to that first item.
I never post questions about these things. I’m always amazed when people take time to answer these sorts of nutty beginner questions. But I’ve been impressed with how inclusive the community seems to be. That said, no worries if you don’t get to this. And thanks again!
February 3rd, 2012 at 9:16 PM
NavBar can be edited in Interface Builder or in your code, during ViewWillAppear, set background I think
You can make tab 2 the split view by refactoring the code, not difficult, but just have to make some changes in the code to get the correct behavior …If you get the code, you will see the few changes and should be able to switch them around
Last item I am not sure about, you can probably tweak it, but be careful not to break something else