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.
Related
I have this buttons controller with buttons xib. This buttons is included in my other views. The problem I have is button clicked navigation.
-(IBAction) gotoReport:(id) sender
{ NSLog(#"ll");
ReportStepOne *report = [[ReportStepOne alloc]init];
[self.navigationController pushViewController:report animated:YES];
[report release];
}
I could see the log message, but navigation doesn't work. I guess I should not use self?
appDelegate.H
UINavigationController *navCon;
appDelegate.M
navCon = [[UINavigationController alloc] init];
[navCon setNavigationBarHidden:YES];
Login *login = [[Login alloc] init];
[navCon pushViewController:login animated:NO];
[login release];
[window addSubview:navCon.view];
[self.window makeKeyAndVisible];
Your first example of IBAction is correct, it should pus the view. If it's not pushing, you need to check your XIB to make sure you have connected the correct button to this IBAction.
in your app delegate, do this instead:
Login *login = [[Login alloc] init];
// Make navController a property..
self.navController = [[UINavigationController alloc] initWithRootViewController:login];
//This is the key..
[[self window] setRootViewController:self.navController];
[self.navController setNavigationBarHidden:YES];
[login release];
[self.window makeKeyAndVisible];
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.
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 trying to push a new viewController into the navigationController from a popoverController but it doesnt work for me.
This is how I call to the popoverController:
PdfDetailViewController *vc=[[PdfDetailViewController alloc] initWithNibName:#"PdfDetailViewController" bundle:nil];
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0,0, 400, 280)];
vc.contentSizeForViewInPopover = CGSizeMake(700, 390);
self.popoverController = [[UIPopoverController alloc] initWithContentViewController:vc];
[self.popoverController presentPopoverFromRect:cell.frame inView:self.tableView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[popoverView release];
[popoverContent release];
This is my code from the popoverController:
CommentsViewController *commentsViewController = [[CommentsViewController alloc] init];
commentsViewController.index = PdfID;
[self.parentViewController.navigationController pushViewController:commentsViewController animated:YES];
[commentsViewController release];
Nothing happen
Please help me... thank you!
UIPopoverController doesn't have a NavigationController unless you add one yourself.
For example
MyViewController *myViewController =
[[MyViewController alloc]
initWithNibName:#"MuViewController"
bundle:[NSBundle mainBundle]];
UINavigationController *navController =
[[UINavigationController alloc]
initWithRootViewController:myViewController];
UIPopoverController *popover =
[[UIPopoverController alloc]
initWithContentViewController:navController];
You should start by cleaning up your code so that it makes sense. Right now you are creating a UIView called popoverView for no reason and then just throwing it away. You're just confusing yourself and it's harder to understand what you are trying to accomplish when you show meaningles code.
Once you've done that, what are you trying to accomplish? Is the problem that this line doesn't work: self.parentViewController.navigationController pushViewController:? If so, I would suggest pulling it apart and logging to make sure that parentViewController and navigationController are the objects you think they are.
I try to change the modalTransitionStyle property of my modal view. Every style work except for FlipHorizontal. If I choose this, nothing happens.
I have an UINavigationController which should be flipped in.
Heres the code:
UINavigationController *loginNavCon = [[UINavigationController alloc] init];
loginNavCon.navigationBar.barStyle = UIBarStyleBlack;
// push login view
LogInViewController *liVC = [[LogInViewController alloc] initWithStyle:UITableViewStyleGrouped];
[loginNavCon pushViewController:liVC animated:NO];
[liVC release];
// show login view
loginNavCon.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.window.rootViewController presentModalViewController:loginNavCon animated:YES];
[loginNavCon release];
Thanks for your help.
Ok, I figured it out!
The point is to set it in the pushing UIViewController, not in the pushed one.
So in my example code it has to look like this:
UINavigationController *loginNavCon = [[UINavigationController alloc] init];
loginNavCon.navigationBar.barStyle = UIBarStyleBlack;
// push login view
LogInViewController *liVC = [[LogInViewController alloc] initWithStyle:UITableViewStyleGrouped];
[loginNavCon pushViewController:liVC animated:NO];
[liVC release];
// show login view
/** changed **/
self.window.rootViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
/*************/
[self.window.rootViewController presentModalViewController:loginNavCon animated:YES];
[loginNavCon release];