App not navigating to second view - iphone

The code I am using
NSLog(#"before Navigate to second activity");
Signature *temp = [[Signature alloc]initWithNibName:#"Signature" bundle:nil];
[self.navigationController pushViewController:temp animated:YES];
NSLog(#"after Navigate to second activity");
On console,both the log statements are getting printed, but my app is not navigating me to the next View.Please correct me.

if you are not using a UINavigationController on your app you can not call pushViewController, use presentViewController:animated:completion: instead:
[self presentViewController:temp animated:YES completion:nil];
for more information check the documentation

The log messages would show anyway, so no surprise there. Add a callback to the delegate for that navigation controller (you must first set a delegate of course) for
navigationController:didShowViewController:animated:
There you can make sure that the viewController passed (make sure Signature is a ViewController instance).

i think your application is not with navigationController so in AppDelegate.m file assign rootViewController like this..
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
RootViewController *viewController1 = [[[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil] autorelease];
UINavigationController *navviewController=[[UINavigationController alloc]initWithRootViewController:viewController1];
self.window.rootViewController = navviewController;
[self.window makeKeyAndVisible];
return YES;
}
after that check its working..

CreditsViewController *viewController = [[CreditsViewController alloc] init];
[[self navigationController] pushViewController:viewController animated:YES];
[viewController release];
you can try with above code

Related

iPhone: pushViewController doesn't work after replacing RootViewController

I wish to place a screen before my curren RootViewController. So far I have made the following modification to MyAppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//with this in the existing RootViewController loads correctly
//self.window.rootViewController = self.navigationController;
self.window.rootViewController = [[[HomePageController alloc] init] autorelease];
}
I'm not entirely sure how self.navigationController actually gets set to my RootViewController. Either way if I make the modification my HomePageController does load correctly, however I am then unable to push another view on top of it. I have a simple button on HomePageController that performs the following (note that HomePageController should load the currently named RootViewController, HomePageController is the view I want to sit above this):
RootViewController *rvC = [[[RootViewController alloc] initWithNibName:#"RootViewController" bundle:[NSBundle mainBundle]] autorelease];
[self.navigationController pushViewController:rvC animated:YES];
When this code runs nothing happens... I'm not entirely sure why, possibly something related to the navigationController? Maybe I havent put HomePageController above RootViewController correctly or in the best way?
You have no navgiationController currently installed.
To fix you have to replace
self.window.rootViewController = [[[HomePageController alloc] init] autorelease];
with
self.window.rootViewController = [[[UINavigatoinController alloc] initWithRootViewController:[[[HomePageController alloc] init] autorelease]] autorelease];
now you have navigationController installed and following
[self.navigationController pushViewController:rvC animated:YES];
will do the right job.

Show View Controller Modally on First Startup

I'd like to have a view with instructions on how to use my app show up on the first time the app is opened. I have handled the problem of the only showing this view on the first startup using NSUserDefaults, but I am having trouble getting the view to display the way I want it to modally, not as the rootViewController. Here is my AppDelegate.m code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
BOOL hasShownStartup = [[NSUserDefaults standardUserDefaults] boolForKey:kAppHasShownStartupScreen];
if (!hasShownStartup) {
[self showInstructions];
}
[self.window makeKeyAndVisible];
return YES;
}
- (void)showInstructions
{
NSLog(#"showing instructions");
InstructionsViewController *howToView = [[InstructionsViewController alloc] initWithNibName:#"InstructionsViewController"
bundle:nil];
self.instructionsViewController = howToView;
[howToView release];
UINavigationController *howtoNavController = [[UINavigationController alloc]
initWithRootViewController:self.instructionsViewController];
self.instructionsViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.viewController presentModalViewController:howtoNavController animated:NO];
[howtoNavController release];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kAppHasShownStartupScreen];
}
I want my rootViewController to remain self.viewController. I want to be able to click 'Done' on the instructionsViewController nav bar to transition back to the rootViewController. Executing the code as written never shows the instructions view. The only way I can see instructionsViewController is if I change the line [self.viewController presentModalViewController:howtoNavController animated:NO]; to self.window.rootViewController = self.instructionsViewController; but this is obviously not what i want (unless I could modally transition back to viewController).
Hopefully I've made it clear enough what I am trying to accomplish. Thanks in advance.
Try moving [self showInstructions]; to applicationDidBecomeActive: instead.
Try putting the [self showInstructions] after [self.window makeKeyAndVisible]:
[self.window makeKeyAndVisible];
if (!hasShownStartup) {
[self showInstructions];
}

UINavigationController not working (pushViewController ignores the view)

there are a lot of questions regarding UINavigationController. I modify my code to follow Apple examples, but the pushViewController method is not working:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window addSubview:navController.view];
[window makeKeyAndVisible];
LoginController *login = (LoginController*)[self.navController.viewControllers objectAtIndex:0];
if([login already_validated] == TRUE) {
self.timeline = [[TimelineViewController alloc] initWithNibName:#"Timeline" bundle:[NSBundle mainBundle]];
[navController pushViewController:timeline animated:YES];
[self.timeline release];
}
return YES;
the view is loaded correctly in the line:
self.timeline = [[TimelineViewController alloc] initWithNibName:#"Timeline" bundle:[NSBundle mainBundle]];
...but
[navController pushViewController:timeline animated:YES];
does not present the view. I've checked and navController is not null.
Any ideas?
Best!
Lucas.
FIXED!!
The problem resides on the MainWindow.xib.
Do NOT set the rootViewController on the window class!
If you set the attribute on the XIB file, this view will be on top of everything else.
You should never send a release to a property directly! Memory management is done in the setter method for you!
instead of:
[self.someProperty release];
write:
self.someProperty = nil;
Normally you do this in the dealloc method.
In your case simply remove the line [self.timeline release]; or don't use a property at all.
EDIT:
add an autorelease:
self.timeline = [[[TimelineViewController alloc] initWithNibName:#"Timeline" bundle:[NSBundle mainBundle]] autorelease];
Try out this one..
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window addSubview:navController.view];
[window makeKeyAndVisible];
LoginController *login = (LoginController*)[navController.viewControllers objectAtIndex:0];//here remove self
if([login already_validated] == TRUE) {
self.timeline = [[TimelineViewController alloc] initWithNibName:#"Timeline" bundle:nil];//remove the nsbundle mainbundle
[navController pushViewController:self.timeline animated:YES];//here u have to use with self.timeline
[self.timeline release];
}
return YES;

Presenting Modal View Controller before window is visible

I would like to present a view controller modally before calling -makeKeyAndVisible on the application's window. However, this code only shows the mainNav view controller:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
MainViewController *main = [[MainViewController alloc] init];
UINavigationController *mainNav = [[UINavigationController alloc] initWithRootViewController:main];
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"Restore"])
{
DetailViewController *detail = [[DetailViewController alloc] init];
UINavigationController *detailNav = [[UINavigationController alloc] initWithRootViewController:detail];
// changing main to mainNav does not help
[main presentModalViewController:learnNav animated:NO];
[detailNav release]; [detail release];
}
self.window.rootViewController = mainNav;
[main release]; [mainNav release];
[self.window makeKeyAndVisible];
return YES;
}
What am I missing?
You should better make the window appear and then present the modal view with animated=NO. What's the point of presenting the modal view before everything else is instantiated and displayed?
Edit
To try to make your code work, here are a couple of hints. Try this:
[mainNav presentModalViewController:learnNav animated:NO];
or this:
[main.navigationController presentModalViewController:learnNav animated:NO];
I'd say that these two methods work best if they're put after the makeKeyAndVisible call.

Adding UINavigationController to existing UIViewController

How do I add an existing UIViewController (which is presented using presentModalViewController) to a UINavigationController?
When user tap on button, a new copy of my detail view need to be pushed. (In other words, pushViewController displaying pushViewController, modally, in a UINavigationController).
Easiest way to enable this functionality?
how do you create your modal viewcontroller? Just wrap the controller into a UINavigationController
Let's assume your modal code is like this:
MyExampleViewController *vc = [[[MyExampleViewController alloc] initWithNibName:#"MyExample" bundle:nil] autorelease];
[self presentModalViewController:vc animated:YES];
Then change it into something like this:
MyExampleViewController *vc = [[[MyExampleViewController alloc] initWithNibName:#"MyExample" bundle:nil] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
[self presentModalViewController:navController animated:YES];
I think you need to add a navigation controller in your delegate, after that you can push the view. So that you can push the view from anywhere in your application.
on AppDelegate.h
UINavigationController *navig;
on AppDelegate.M
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
navig = [[UINavigationController alloc] initwithRootViewController:viewController.view];
//[navig pushViewController:viewController animated:YES];
[self.window addSubview:navig.view];
[self.window makeKeyAndVisible];
return YES;
}