I tried to present a modal view controller on a view did load.
Here's the code:
if (!self.loginNavViewController_){
AHLoginViewController * loginVC = [[AHLoginViewController alloc] initWithNibName:#"AHLoginViewController" bundle:nil];
/*
AHTestViewController * test = [[AHTestViewController alloc] initWithNibName:#"AHTestViewController" bundle:nil];
*/
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:loginVC];
navController.modalPresentationStyle = UIModalPresentationFullScreen;
navController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
navController.title = #"Login to Instagram";
self.loginNavViewController_ = navController;
[self presentModalViewController:self.loginNavViewController_ animated:YES];
if (self.loginNavViewController_ == nil){
NSLog(#"NIL");
} else {
NSLog(#"NOT NIL");
}
}
However I don't see a modal view controller being shown. Why??
A view controller receives viewDidLoad immediately after loading the view and before the view is inserted into a view hierarchy. In other words, it cannot present a modal view controller because its own view is not in any window yet.
Try to do that in viewWillAppear: or viewDidAppear: instead.
I Think you can use in view did load also I am already using this.
InfoViewController *infoViewController = [[InfoViewController alloc]initWithNibName:#"InfoViewController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:infoViewController];
[self.navigationController.view addSubview:nav.view];
you add many model on main view using view did load.
Welcome.
Related
I have an alternative flow in my app. This flow starts in my firstViewController, then in this view a call my secondViewController like this:
- (IBAction)PressButton:(id)sender {
SecondViewController *second = [[SecondViewController alloc] init];
second.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
UINavigationController *nav = self.navigationController;
[nav presentViewController:second animated:YES completion:nil];
}
In my secondViewController I want to push my thirdViewController. But it is not working I tried this ways:
- (IBAction)pressButton:(id)sender {
ThirdViewController *tvc = [[ThirdViewController alloc] init];
UINavigationController *nav = self.navigationController;
[nav pushViewController:tvc animated:YES];
}
When I press the button of secondViewController nothing happens.
What I'm doing wrong ?
I'm using:
OSX 10.8.2
Xcode 4.6
iOS 6.1
You must present the navigation controller modally, and have the second view as the root of that navigation controller. As well as calling presentViewController from the owning view not its parent navigation controller.
- (IBAction)PressButton:(id)sender {
SecondViewController *second = [[SecondViewController alloc] init];
second.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:second];
[self presentViewController:navigationController animated:YES completion:nil];
}
Instead of presenting just the second view controller, make sure to present an additional navigation controller.
SecondViewController *secondViewController = [[SecondViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
[[self navigationController] presentViewController:navigationController animated:YES completion:nil];
If you are using storyboard just click on the source view xib, Ctrl+drag to destination (Create Segue), select modal from popup menu.Click on the newly created connection. Add a name for it then in source view controller [self performSegueWithIdentifier:#"Segue Name" sender:self];
If you are trying to get a button to direct you to a different page modally, you can go into the storyboard or xib file. Control click from that button to the view controller you want to go to. and then the popup menu will give you the options of what type of outlet you want to use. Hope this helps
I have a problem with the view deck library and the navigation controller, the app crashes when I press the back button with a popviewcontroller.
Is there someone who has added the view deck with a navigation controller present in their app?
I've inizializes the deckView in this way:
LeftViewController *leftViewController = [[LeftViewController alloc]initWithNibName:#"LeftViewController" bundle:[NSBundle mainBundle]];
CentraController *centralViewController = [[CentraController alloc]initWithNibName:#"CentraController" bundle:[NSBundle mainBundle]];
self.deckController = [[IIViewDeckController alloc]initWithCenterViewController:centralViewController leftViewController:leftViewController];
self.deckController.leftLedge = 100;
self.deckController.navigationControllerBehavior = IIViewDeckNavigationControllerContained;
[self.navigationController initWithRootViewController:deckController];
[window setRootViewController:self.navigationController];
Use the source luke:
ViewController *centerController = [[ViewController alloc]initWithNibName:#"ViewController" bundle:nil];
self.centerController = [[UINavigationController alloc]initWithRootViewController:centerController];
IIViewDeckController* deckController = [[IIViewDeckController alloc] initWithCenterViewController:self.centerController leftViewController:self.leftController rightViewController:rightController];
I am new to iphone. I have a small confusion on uinavigation controllers that is I want a navigation bar in initial view controller in that view controller there is a button in navigation bar when we click on that it will push the another view controller(second view controller) from that there is a back button if we click on that i want to pop that view controller and come back to initial view controller.If any body know this please help me .If you explain with some code it will better to understand us.
The following code i have written so,far here present modal view controller and dismiss model view controller is working but pushview controller and popview controller is not working
In appDelegate i have written like this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//create a window
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//biblePlayerController is an instance of BiblePlayerViewController class and then set the biblePlayerController as a rootViewController to the window
self.biblePlayerController = [[BiblePlayerViewController alloc] initWithNibName:#"BiblePlayerViewController" bundle:nil];
navigationController = [[UINavigationController alloc]initWithRootViewController:self.biblePlayerController];
// self.window.rootViewController = self.biblePlayerController;
[self.window addSubview:navigationController.view];
//make the window visible
[self.window makeKeyAndVisible];
return YES;
}
//In initial View controller there is a navigation on that there is a download button code for that is
//BiblePlayerViewController.m
UIBarButtonItem *downloadButton = [[UIBarButtonItem alloc] initWithTitle:#"Download" style:UIBarButtonItemStylePlain target:self action:#selector(gotoProgressViewController:)];
self.navigationItem.rightBarButtonItem = downloadButton;
- (IBAction)gotoProgressViewController:(id)sender {
#try {
//ShowProgressViewCont is initialized with the nibName
showProgressViewController = [[ShowProgressViewCont alloc]initWithNibName:#"ShowProgressViewCont" bundle:nil];
//UINavigationController is initialized with the rootViewController showProgressViewController
navigationController = [[UINavigationController alloc]initWithRootViewController:showProgressViewController];
//The transition style of the navigationController is set to UIModalTransitionStyleCrossDissolve
navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
//Presents a modal view managed by the given view controller to the user.Here navigation Controller that manages the modal view.
[self presentModalViewController:navigationController animated:YES];
// [navigationController pushViewController:showProgressViewController animated:YES];
}
#catch(NSException * e){NSLog(#"Exception At10: %s %d %s %s %#",__FILE__,__LINE__,__PRETTY_FUNCTION__,__FUNCTION__,e);}#finally{}
}
In the above code presentModalViewController is working but pushViewController is not working why. If any body know this please help me..
Suppose you are in ParentViewController and by pressing Child Btn you want to go to ChildViewController.
- (void) childBtnPressed : (id) sender
{
ChildViewController *makeNewObject = [[ChildViewController alloc] initWithNibName:#"ChildViewController" bundle:nil];
[self.navigationController pushViewController:makeNewObject animated:YES];
[makeNewObject release];
}
Now in your ChildViewController.m file, write this on the Back Btn action to go back to the Parent View Controller.
- (void) backBtnPressed : (id) sender
{
[self.navigationController popViewControllerAnimated:YES];
}
On clicking the button in the Navigationbar, Push nextview
- (IBAction)NextViewAction:(id) sender
{
NextViewController *NxtView = [[NextViewController alloc] initWithNibName:#"NextViewController" bundle:nil];
[self.navigationController pushViewController:NxtView animated:YES];
[NxtView release];
}
To Pop from NextViewController
[self.navigationController popViewControllerAnimated:YES];
I am editing my question that i had programetically add the tabbar as shown below:-
FirstViewController *obj_FirstViewController = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
SecondViewController *obj_SecondViewController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
ThirdViewController *obj_ThirdViewController = [[ThirdViewController alloc] initWithNibName:#"ThirdViewController" bundle:nil];
navigation1 = [[UINavigationController alloc] initWithRootViewController:obj_FirstViewController];
navigation2 = [[UINavigationController alloc] initWithRootViewController:obj_SecondViewController];
navigation3 = [[UINavigationController alloc] initWithRootViewController:obj_ThirdViewController];
MainTabBar = [[UITabBarController alloc] init];
MainTabBar.delegate=self;
[MainTabBar setViewControllers:[NSArray arrayWithObjects:navigation1,navigation2,navigation3,nil]];
MainTabBar.view.frame=self.view.frame;
MainTabBar.selectedIndex=0;
[self.view addSubview:MainTabBar.view]
By writing this in (void)viewDidLoad i got the 3 tab in my viewcontroller.But the problem is i want to set the name of the tab as
Home
Favorites
About us
I had tried by writing the below code:-
obj_FirstViewController.tabBarItem.title=#"Home";
self.title = #"My View Controller";
But this does not work - can anyone please help me how to do this programatically? Where to write the line so that i get this 3 name in my tab bar
this is how I made it
1) I made a view controller with your tabbar
2) added view controllers for each tab and a method to the tabbar view controller class:
-(void)updateContentsWithViewController:(UIViewController *)insideViewController
the method is called when a tabbutton is pressed.
3) here is the code for the switching
- (void)updateContentsWithViewController:(UIViewController *)insideViewController {
//internalViewController is the viewController which you change
[internalViewController.view removeFromSuperview];
[internalViewController release];
internalViewController = [insideViewController retain];
navController = [[UINavigationController alloc] initWithRootViewController:insideViewController];
[navController setNavigationBarHidden:YES];
[navController.view setFrame:CGRectMake(0, 0, 320, 348)];
//frame I needed in my app .. can be changed
[self.internalView addSubview: navController.view];
//navController is the property for the navigationController
[self.view sendSubviewToBack: self.internalView];
}
its possible add tabBar in separate view controller which will be like rootview controller ,then in viewDidLoad of the root view controller assign the object of tabbar created to a appdelegate tabBar declared ...then use appdelegate tabbar for other navigation's alone .
I am working with push notifications. i am trying to create and push a DetailView in the navigationController when action button in notification is clicked. but navigationController is nil. how can i put that DetailView in the navigationController? I want to push RootViewController in the navigationController and then the DetailView. how can i do that?
in AppDelegate:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
RootViewController *controller = [[RootViewController alloc] init];
//getting warnings here.(Unused variable navigationController)
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
[controller doStuff];
[controller release];
}
in RootViewController:
-(void)doStuff{
[[self stories] removeAllObjects];
[self startParsing];
[self.tableView reloadData];
DetailViewController *detail = [[DetailViewController alloc] init];
//custom code
[self.navigationController pushViewController:detail animated:YES];
[detail release];
this is the code i m using right now. and plz notice that i have
[self.tableView reloadData];
Okay, now I am pretty sure I understand the issue. The problem is, you never manually set the navigationController property on a UIViewController. The navigationController property is nil if the view controller is not under a navigation controller and if it is, then the property points to it.
What you need to do, is when you display your root view controller, instead of directly displaying its view, add it to a navigation controller, then display the navigation controller's view. Like so:
RootViewController *controller = [[RootViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
//Here you would display navigationController.view somehow
So, after you have your root view controller in a navigation controller, in a method in root view controller you can do this:
DetailViewController *detail = [[DetailViewController alloc] init];
//Do whatever you need to do to set values on the detail view controller
[self.navigationController pushViewController:detail animated:YES];
The key thing is this: you need to put the root view controller into a navigation controller before you can access a navigation controller from within root view controller.
If your nav controller is nil, it needs creating and then you place things into it.
Try this:
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[navController pushViewController:detailViewController animated:NO]; // or YES
If you start out with no UINavigationController and want to display it with more than one view controller in its stack, after initing the navigation controller you can set the viewControllers property to an array with the various view controllers you want.
edit: some example code:
UINavigationController *navController = [[UINavigationController alloc] init];
NSArray *viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
[navController setViewControllers:viewControllers animated:NO];
After doing that, your navigation controller will have viewController2 on top and viewController1 behind it.
Alternately, you could do it this way:
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController1];
[navController pushViewController:viewController2 animated:NO];