Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mikezang

macrumors 6502a
Original poster
May 22, 2010
854
7
Tokyo, Japan
I have a tab bar controller, and I want to use a split view controller in one tab, I tried to select view controller in inspector, but there is no UISplitViewController, and I tried to inset a UISplitViewController and failed, how can I use UISplitViewController in UITabBarController?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Basically you can't do what you are trying to do: the split view controller must be the outer most controller (i.e. the one directly within the window). The best you can do is hide the over view when other tabs are selected.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
What do you mean?

I mean exactly what I said. I chose the words carefully after all.

You must have the UISplitViewController as the top-level view controller. It will not allow it's view to be placed inside any other view controllers view. So if you want to use it you must put the tab view controller within the split view controller as either master or detail. Assuming you set the tab controller as master (the larger of the two views) you simply hide the detail view (look at the documentation) for all tabs other than the one you want to show the split on.
 

mikezang

macrumors 6502a
Original poster
May 22, 2010
854
7
Tokyo, Japan
Yeah, I understood your mean except last one.

I found some samples to talk about use split in tabbar, for example, but my tabbar has others view controller, I just want to add a new tab with splitview, but I am not sure how to keep other tabs what I made in IB, that is my question
http://stackoverflow.com/questions/2475139/uisplitviewcontroller-in-a-tabbar-uitabbarcontroller

http://markivsblog.blogspot.com/2010/04/retrofitting-ipad-uisplitviewcontroller.html

http://stackoverflow.com/questions/2846349/multi-level-navigation-controller-on-left-hand-side-of-uisplitview-with-a-small-t
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
I have explained what I would do. This would prevent the problems with iOS 3.2 as discussed in one of those links. I don't use IB so you'll forgive me if I don't try and answer anything to do with that.
 

newtoiphonesdk

macrumors 6502a
Jul 30, 2010
567
2
Please let me know if you get something figured out with this. I have been trying to do the same thing. Unfortunately, there is rarely a time when anyone on MacRumors will answer with anything useful. They all seem to like to google whatever your question is and post a link instead of real help. And if you dare ask them for an example they get tight-lipped and think you should take a full course on programming instead of them spending 5 minutes to help. I actually found one guy who went to the trouble of posting about 5 links on how to email from within app in response to a question of how to do that, instead of just posting the UISharedApplication mailto:"@yahoo" code. Very rude folks here.
 

mikezang

macrumors 6502a
Original poster
May 22, 2010
854
7
Tokyo, Japan
Thanks, guy, you said what I thought!

I have more than 20 years experience in Windows and only half year in Mac.

I never met such forums in past years when I ask something for Windows programming, but here like you said, no experts want to answer your question, they just tell you to google, I am not sure if this is Apple's fashion or they thought they are experts and no paitiant answer anything?!

Anyway, this way is not good for communication....
 

Anne R. Kist

macrumors newbie
Aug 11, 2010
19
0
...in the UK
Code:
UISplitViewController *splitViewController = [[UISplitViewController alloc] init];
[tabBarController.view addSubview:splitViewController.view];
 

mikezang

macrumors 6502a
Original poster
May 22, 2010
854
7
Tokyo, Japan
I got it but not complete, there is no button for popover and..., anyway, this is a little step, I will show your after I got full splitView.
 

Attachments

  • SnapShot 2010-08-12 at 14.28.26.jpg
    SnapShot 2010-08-12 at 14.28.26.jpg
    63 KB · Views: 282
  • SnapShot 2010-08-12 at 14.28.50.jpg
    SnapShot 2010-08-12 at 14.28.50.jpg
    35.5 KB · Views: 198
  • SnapShot 2010-08-12 at 14.29.13.jpg
    SnapShot 2010-08-12 at 14.29.13.jpg
    65.5 KB · Views: 229
  • SnapShot 2010-08-12 at 14.28.59.jpg
    SnapShot 2010-08-12 at 14.28.59.jpg
    44 KB · Views: 252

mikezang

macrumors 6502a
Original poster
May 22, 2010
854
7
Tokyo, Japan
I walked one more step, now when I selected row in master view on landscape mode, the detail view will show detail information.
The rest problem is detailView can not act for <UIPopoverControllerDelegate, UISplitViewControllerDelegate> on portrait mode.

Do you have any suggestion?
 

Attachments

  • SnapShot 2010-08-12 at 17.46.50.jpg
    SnapShot 2010-08-12 at 17.46.50.jpg
    34.6 KB · Views: 156
  • SnapShot 2010-08-12 at 17.46.41.jpg
    SnapShot 2010-08-12 at 17.46.41.jpg
    45 KB · Views: 210

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
I got it but not complete, there is no button for popover

That's not related to the tab-bar thing: you always have to add that yourself. For whatever reason Apple did not make it automatic. You may have some fun doing this on first run as you cannot assume the orientation of the device...
 

mikezang

macrumors 6502a
Original poster
May 22, 2010
854
7
Tokyo, Japan
I did it in my detail view controller, but I am not sure why the methods don"t be called, this is my next task. do you have any idea?
Code:
#pragma mark -
#pragma mark Split view support

- (void)splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc {
    barButtonItem.title = @"Master List";
    NSMutableArray *items = [[toolbar items] mutableCopy];
    [items insertObject:barButtonItem atIndex:0];
    [toolbar setItems:items animated:YES];
    [items release];
    self.popoverController = pc;
}


// Called when the view is shown again in the split view, invalidating the button and popover controller.
- (void)splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
    NSMutableArray *items = [[toolbar items] mutableCopy];
    [items removeObjectAtIndex:0];
    [toolbar setItems:items animated:YES];
    [items release];
    self.popoverController = nil;
}
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
What is toolbar? Is it visible on the screen? I don't see it in your screenshots (unless it's the grey bar at the top of the detail: I assumed that was a navigation bar).
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
OK. Are the methods being called at all (put an NSLog in to check)? If not is the object (the detail view controller I assume) the delegate of the UISplitViewController?
 

mikezang

macrumors 6502a
Original poster
May 22, 2010
854
7
Tokyo, Japan
I did debug and log, they never be called.
Code:
@interface StockDetailController : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate> {
    UIPopoverController *popoverController;
    UIToolbar *toolbar;
    
    id detailItem;
    UILabel *detailDescriptionLabel;
}
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
You have declared that the class implements the delegate protocol. This in no way implies that the actual instance of the class is the delegate of any instance of UISplitViewController: you must set the delegate property of the split view controller instance. This is normal: it is like this for every single Cocoa/Cocoa Touch class that has a delegate.
 

mikezang

macrumors 6502a
Original poster
May 22, 2010
854
7
Tokyo, Japan
Thanks for your suggestion, now I got what I need.
 

Attachments

  • SnapShot 2010-08-12 at 20.15.45.jpg
    SnapShot 2010-08-12 at 20.15.45.jpg
    47.2 KB · Views: 180
  • SnapShot 2010-08-12 at 20.15.54.jpg
    SnapShot 2010-08-12 at 20.15.54.jpg
    34.8 KB · Views: 152

biko01

macrumors newbie
Sep 10, 2009
4
0
How did you fit this splitview into tab bar?

Mikezang, how did you get this Splitview to show up instead of Navigation or View controller when tab bar item selected? Your image show exactly what I was chasing but no info how it was done?
 

mikezang

macrumors 6502a
Original poster
May 22, 2010
854
7
Tokyo, Japan
Mikezang, how did you get this Splitview to show up instead of Navigation or View controller when tab bar item selected? Your image show exactly what I was chasing but no info how it was done?
Put makeSplitViewController in applicationDidLaunch method and copy master and detail view controllers from SplitViewController template.
Code:
@interface StockManagerAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    UITabBarController *tabBarController;
    UISplitViewController *splitViewController;
    UINavigationController *navigationController;
    StockMasterController *stockMasterController;
    StockDetailController *stockDetailController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@property (nonatomic, retain) IBOutlet UISplitViewController *splitViewController;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) IBOutlet StockMasterController *stockMasterController;
@property (nonatomic, retain) IBOutlet StockDetailController *stockDetailController;

@end

Code:
#import <UIKit/UIKit.h>

@class StockDetailController;

@interface StockMasterController : UITableViewController {
    StockDetailController *stockDetailController;
}

@property (nonatomic, retain) IBOutlet StockDetailController *stockDetailController;

@end

Code:
-(void) makeSplitViewController {
    NSMutableArray *controllers = [NSMutableArray arrayWithArray:tabBarController.viewControllers];
    int index = 0;
    
    for (UIViewController *controller in tabBarController.viewControllers) {
        if ([controller.tabBarItem.title isEqualToString:@"Stock"]) {
            stockDetailController = [[StockDetailController alloc] initWithNibName:@"StockDetailController" bundle:nil];
            
            stockMasterController = [[StockMasterController alloc] initWithStyle:UITableViewStylePlain]; 
            stockMasterController.navigationItem.title = date;
            stockMasterController.stockDetailController = stockDetailController;
            
            UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:stockMasterController] autorelease];
            
            splitViewController = [[UISplitViewController alloc] init];
            splitViewController.tabBarItem = controller.tabBarItem;
            splitViewController.viewControllers = [NSArray arrayWithObjects:nav, stockDetailController, nil];
            splitViewController.delegate = stockDetailController;
            
            [controllers replaceObjectAtIndex:index withObject:splitViewController];
        }
        
        index++;
    }
    
    tabBarController.viewControllers = controllers;
}
 

thepost

macrumors newbie
Nov 18, 2010
3
0
Toronto
There's no way to do this for the first tab though, to replace the first index of the tab bar controller results in an error:

'NSRangeException', reason: '*** -[NSCFArray removeObjectAtIndex:]: index (0) beyond bounds (0)'
 

mikezang

macrumors 6502a
Original poster
May 22, 2010
854
7
Tokyo, Japan
There's no way to do this for the first tab though, to replace the first index of the tab bar controller results in an error:

'NSRangeException', reason: '*** -[NSCFArray removeObjectAtIndex:]: index (0) beyond bounds (0)'
Why? in my app, I used it in first tab.
 

Attachments

  • SnapShot 2010-11-24 at 21.41.54.jpg
    SnapShot 2010-11-24 at 21.41.54.jpg
    46.7 KB · Views: 144
  • SnapShot 2010-11-24 at 21.42.02.jpg
    SnapShot 2010-11-24 at 21.42.02.jpg
    44.2 KB · Views: 150

mikezang

macrumors 6502a
Original poster
May 22, 2010
854
7
Tokyo, Japan
Why? in my app, I used it in first tab.
If you use it in first tab with Landscape, you have to add code as below to RootViewController.m
Code:
(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    self.navigationController.toolbar.hidden = YES;
    self.navigationController.navigationBar.top = 0;
}
l
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.