I am using the split View functionality in my app.I have to put tabbar in rootViewController.
But when I add controllers in tabbar and add them into split view it doesnt split.
It only shows detailViewController.
Here is the code in application did finish launching:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
UIViewController *viewController2,*viewController3,*viewController4;
rootViewController = [[[CategoryItemsList alloc] init] autorelease];
viewController2 = [[[SearchList alloc] init] autorelease];
viewController3 = [[[FavoritesList alloc] init] autorelease];
viewController4 = [[[Information alloc] init] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects: rootViewController,viewController2,viewController3,viewController4, nil];
splitDetail = [[splitDetailView alloc] initWithNibName:#"splitDetailView" bundle:nil];
UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:tabBarController];
splitViewController = [[UISplitViewController alloc] init];
// splitViewController.tabBarItem = controller.tabBarItem;
splitViewController.viewControllers = [NSArray arrayWithObjects:nav, splitDetail, nil];
splitViewController.delegate=splitDetail;
rootViewController.splitView=splitDetail;
}
You can refer to this links. I think this is what you are looking out for:
https://github.com/mattgemmell/MGSplitViewController
http://www.raywenderlich.com/1040/ipad-for-iphone-developers-101-uisplitview-tutorial
http://mikebluestein.wordpress.com/2010/04/03/using-a-uisplitviewcontroller-to-create-a-master-detail-ipad-app-with-monotouch/
Once you add the split view then you just need to add the object of the SplitViewController to the TabBarController as one of the viewControllers
Hope this helps.
Related
I am trying to include a navigation controller within the third tab of my tabbarcontroller. I have had some feedback but am only able to get about this far. The code below doesn't produce any errors, but does not seem to work as the app just quits out. Does anyone have any input on what I might be doing wrong?
UIViewController *viewController1 = [[FirstViewController alloc]
initWithNibName:#"PDCFirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc]
initWithNibName:#"SecondViewController" bundle:nil];
viewController3 = [[UIViewController alloc] initWithNibName:#"ThirdViewController"
bundle:nil];
UINavigationController *navigationcontroller = [[UINavigationController alloc]
initWithRootViewController:viewController3];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray
arrayWithObjects:viewController1,viewController2,navigationcontroller, nil];
Thank you all!
int main(int argc, char *argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([PDCAppDelegate class]));
}
}
Make sure with all nib names you are using and also with class name, i.e.
if you class name of UIViewController is FirstViewController, nib name should be same. And you have used "PDCFirstViewController" for nib name.
Same with ThirdViewController & SecondViewController.
Try below code...
FirstViewController *viewController1 = [[FirstViewController alloc]
initWithNibName:#"FirstViewController" bundle:nil];
SecondViewController *viewController2 = [[SecondViewController alloc]
initWithNibName:#"SecondViewController" bundle:nil];
ThirdViewController *viewController3 = [[ThirdViewController alloc] initWithNibName:#"ThirdViewController"
bundle:nil];
UINavigationController *navigationcontroller = [[UINavigationController alloc]
initWithRootViewController:viewController3];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray
arrayWithObjects:viewController1,viewController2,navigationcontroller, nil];
Here is the solution
UIViewController *courseView = [[[CoursesView alloc] initWithNibName:#"CoursesView" bundle:nil] autorelease];
UIViewController *subjectViewController = [[[SubjectViewController alloc] initWithNibName:#"SubjectViewController" bundle:nil] autorelease];
UIViewController *videoViewController = [[[VideoViewController alloc] initWithNibName:#"VideoViewController" bundle:nil] autorelease];
UIViewController *quizViewController = [[[QuizViewController alloc] initWithNibName:#"QuizViewController" bundle:nil] autorelease];
UIViewController *proifileViewController = [[[Profile2ViewController alloc] initWithNibName:#"Profile2ViewController" bundle:nil] autorelease];
UINavigationController *coursNav = [[UINavigationController alloc] initWithRootViewController:courseView];
UINavigationController *subjectNav = [[UINavigationController alloc] initWithRootViewController:subjectViewController];
UINavigationController *videoNav = [[UINavigationController alloc] initWithRootViewController:videoViewController];
UINavigationController *quizNav = [[UINavigationController alloc] initWithRootViewController:quizViewController];
UINavigationController *profileNav = [[UINavigationController alloc] initWithRootViewController:proifileViewController];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = #[coursNav, subjectNav,videoNav,quizNav,profileNav];
self.tabBarController.navigationController.navigationBarHidden=YES;
self.tabBarController.delegate=self;
[self.window addSubview:self.tabBarController.view];
[self.window makeKeyAndVisible];
it works for me
I have a custom UITabBarController. On it I have added 3 view controllers adding a navigationController to each one first. It looks like this
ยท customTabBarController.m viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
FirstViewController *firstController = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
UINavigationController *firstNavController = [[UINavigationController alloc] initWithRootViewController:firstController];
SecondViewController *secondController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
UINavigationController *secondNavController = [[UINavigationController alloc] initWithRootViewController:secondController];
self.viewControllers = [NSArray arrayWithObjects:firstNavController, secondNavController, nil];
[self addLeftButtonImage];
[self addRightButtonImage];
self.selectedIndex = 1;
}
Now, when I am on a view controller and I want to pushViewController, how do I have to call it?
I'm adding a UIViewController to a UINavigationController and then setting a UIPopoverController's view to the UINavigationController. Everything is working great except that I don't get a navigationBar at the top of the popoverController. I'm creating everything like this:
QueryViewController *puvc = [[QueryViewController alloc] autorelease];
UINavigationController *nc = [[UINavigationController alloc] autorelease];
[nc pushViewController:puvc animated:YES];
self.popUp = [[[UIPopoverController alloc] initWithContentViewController:nc] autorelease];
[self.popUp presentPopoverFromBarButtonItem:[self.toolbarItems objectAtIndex:0] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
self.popUp.delegate = self;
I've tried to set navigationBarHidden = NO and it still doesn't show up. I have this code in my viewDidLoad of my QueryViewController:
self.contentSizeForViewInPopover = CGSizeMake(500.0, 500.0);
self.title = #"Queries";
Is there something that I'm missing to display the navigationBar? I am already in a UINavigationController for my main screen, could this be part of my problem?
QueryViewController *puvc = [[QueryViewController alloc] autorelease];
UINavigationController *nc = [[UINavigationController alloc] autorelease];
Maybe your code is wrong. Where is init methods?
You have to init both your QueryViewController and UINavigationController. For the second use initWithRootViewController method.
QueryViewController *puvc = [[[QueryViewController alloc] init] autorelease];
UINavigationController *nc = [[[UINavigationController alloc] initWithRootViewController:pucv] autorelease];
//[nc pushViewController:puvc animated:YES];
If you use initWithRootViewController it's not necessary to push puvc instance.
You could try also this (I like to release memory explicity, not using autorelease).
QueryViewController *puvc = [[QueryViewController alloc] init];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:pucv];
//[nc pushViewController:puvc animated:YES];
Then at the end of your code snippet remember to release puvc and nc.
[puvc release];
[nc release];
P.S. Check the code because I've written without XCode.
I'm trying to put an UITabBarController inside an UINavigationController (Programmatically), this is my code:
UITabBarController *tabBarController = [[UITabBarController alloc] init];
HomeViewPhone *home = [[HomeViewPhone alloc] initWithStyle:UITableViewStylePlain];
home.title = NSLocalizedString(#"HOME",nil);
EventiPhone *eventi = [[EventiPhone alloc] initWithStyle:UITableViewStylePlain];
eventi.title = NSLocalizedString(#"EXPLORE", nil);
FavoritiPhone *favoriti = [[FavoritiPhone alloc] initWithStyle:UITableViewStylePlain];
favoriti.title = NSLocalizedString(#"FAVORITES",nil);
ProfiloPhone *profilo = [[ProfiloPhone alloc] initWithStyle:UITableViewStylePlain];
profilo.title = NSLocalizedString(#"PROFILE", nil);
[tabBarController setViewControllers:[NSArray arrayWithObjects:home,eventi,favoriti,profilo, nil]];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:tabBarController];
[self.window addSubview:navController.view];
but when I tap on one TabBarItem the app crash with this error
-[__NSCFString _tabBarItemClicked:]: unrecognized selector sent to instance 0x7934db0
Any ideas?
Use
self.window.rootViewController = tabBarController;
Instead of
[self.window addSubview:navController.view];
Then add navBarControllers to any of the tabs that need them.
With ARC : solved with #property too !
More complicated app I have : AppDelegate -> NavigationController -> TableViewController -> TabBarController
First in AppDelegate, build the TableViewCtrl and insert in the NavCtrl
TableViewController *myTVC = [[TableViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *myNC = [[UINavigationController alloc] initWithRootViewController:myTVC];
[self.window setRootViewController:myNC];
Second, in TableViewCtrl method didSelectRow (for my use), pushViewController to the TabBarCtrl
_myTBC = [[TabBarController alloc] init];
[[self navigationController] pushViewController:_myTBC animated:YES];
Last, property the TabBarController in .h : that's the key !
#property (retain, nonatomic) UITabBarController * TabBar;
and build the .m, do your own...
ViewController1 *VC1 = [[ViewController1 alloc] init];
ViewController2 *VC2 = [[ViewController2 alloc] init];
_TabBar = [[UITabBarController alloc] init];
NSArray *table = [NSArray arrayWithObjects:VC1,VC2,nil];
[_TabBar setViewControllers:table animated:YES];
[[self view] addSubview:[_TabBar view]];
That's work nice! Doesn't need modal or other stuff...
![I am creating a tab bar controller programmatically:
tabBarController = [[UITabBarController alloc] init];
FirstViewController* vc1 = [[FirstViewController alloc] init];
SecondViewController* vc2 = [[SecondViewController alloc] init];
vc1.title = #"Dallas";//[[NSUserDefaults standardUserDefaults] objectForKey:#"Citynamefrmhome"];
vc1.tabBarItem.image = [UIImage imageNamed:#"Dealss.png"];
vc2.title = #"My Vouchers";
vc2.tabBarItem.image = [UIImage imageNamed:#"nav_voucher_S.png"];
NSArray* controllers = [NSArray arrayWithObjects:vc1,vc2, nil];
tabBarController.viewControllers = controllers;
[self.view addSubview:tabBarController.view];
[vc1 release];
[vc2 release];
if I load it when the app starts, it looks great (look at figure 1):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
autoMagically = [[AutoMagically alloc] initWithNibName:nil bundle:nil];
//self.window.rootViewController = self.dummyView;
[self.window addSubview:autoMagically.view];
[self.window makeKeyAndVisible];
return YES;
}
if I load it when a button is clicked, the way i wanna do it, it looks like figure 2. See how the titles arent showing and the buttons seem to be getting cutoff:
- (void)LoadView
{
AutoMagically *autoMagic = [[AutoMagically alloc]
initWithNibName:nil bundle:nil];
self.autoMagically = autoMagic;
[self.view insertSubview:autoMagic.view atIndex:0];
[autoMagic release];
}
Does anyone know why this is behaving like this?]1
You can call
[[[self.parentViewController.tabBarController.tabBar.items objectAtIndex:/*a number based on what tab it was ex: 2*/]setTitle:#"string"];
in your -viewDidLoad or -awakeFromNib methods. It might be better to use the latter instead of the former.