How is it possible to come back to the same page? - objective-c

I am new at Objective C. I am just trying to build an iphone app. I have created some NIB file, and i have gone to other NIB file by creating an object and using this code:
scoreViewController *sviewController = [[scoreViewController alloc] initWithNibName:#"scoreViewController" bundle:nil];
self.scoreView = sviewController;
[sviewController release];
// Setup the animation
[self.navigationController pushViewController:self.scoreView animated:YES];
Now I want to come back to the same page. For this case I have done the same work, but it does not work when I add the previous page header file name.
mainViewController *mainviewController = [[mainViewController alloc] initWithNibName:#"mainViewController" bundle:nil];
self.mcoreView = mainviewController;
[mainviewController release];
// Setup the animation
[self.navigationController pushViewController:self.mcoreView animated:YES];
So, I will be most grateful if you were so nice to post your comment.

I am not 100% sure what you are asking, but I think you want to go back from the the second controller to the first. What you are doing here is instantiating a second instance of the first controller (so you now have 3 controllers), and pushing it onto the stack. Assuming I have this correct, then if you want to move back to the first controller you should be popping the second controller off the stack, not adding a 3rd:
//mainViewController *mainviewController = [[mainViewController alloc] initWithNibName:#"mainViewController" bundle:nil];
//self.mcoreView = mainviewController;
//[mainviewController release];
// Setup the animation
[self.navigationController popViewControllerAnimated:YES];

Related

pushviewcontroller after uiwebview finishes its load

I am properly pushing viewController B from A using navigationController. However, I would like to do it once uiwebview from viewController B finishes its load and not immediately. I tried firstly init B and push A when load ends but with no success, controller is not viewed. How can it be done? thank you.
from controllerA,
self.controllerB = [[BViewController alloc] initWithNibName:#"BViewController" bundle:nil anUser:self.idUser aLang:self.lang];
//[[self navigationController] pushViewController:controllerB animated:NO]; working if pushed directly here
[self.controllerB view];
then, controllerB is initialized, viewDidLoad triggered and when webviewDidFinishLoad, B must be pushed now or viewed at front.
- (void)webViewDidFinishLoad:(UIWebView*)theWebView
{
AViewController *theInstance = [[AViewController alloc] init];
[theInstance pushBcontroller]; }
on AViewController,
-(void)pushBcontroller{
[[self navigationController] pushViewController:self.controllerB animated:NO];
}
not working...
The line AViewController *theInstance = [[AViewController alloc] init]; creates a new instance of a AViewController. Since it's new it isn't part of the view controller hierarchy and is therefore not connected to the navigation controller.
Give your BViewController a reference to the previous controller and use that instead of creating a different one. Or, perhaps better, send a notification when loading is done that the original AViewController uses to know when to change the display.

When do views get created?

I apologize in advance for the n00b question. I am just getting started w/ iOS!
I am trying to push a webViewController onto a navigation controller.
mudWebViewController *webViewController = [[mudWebViewController alloc] initWithNibName:nil bundle:nil];
[[webViewController webView] setDelegate:webViewController];
[[self navigationController] pushViewController:webViewController animated:YES];
But this doesn't seem to work, as I don't see any of the logs in the delegate messages.
If I set the delegate in the viewDidLoad: method, it works fine.
I guess the webView doesn't actually exist at that point, but why? If I initialize the controller, shouldn't the webView be initialized too?
Is viewDidLoad: the right place to be setting up this stuff?
initWithNibName should be not nil, since you obviously are using a nib file to build the view, else you have to create the view in code, which you don't
mudWebViewController *webViewController = [[mudWebViewController alloc] initWithNibName:#"webViewController" bundle:nil];
[[self navigationController] pushViewController:webViewController animated:YES];
Also any delegates should be set either from the Interface builder or from the view itself in the viewDidLoad delegate and not from the previous class, as the object might not been yet initialized in the code so it can fail to set the delegate properly.

How to remove multiple many view from superview

I have some uiview, one call another in this way:
From first uiview:
MyViewController *contr1 = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
[self.view addSubview:contr1.view];
From second uiview:
MyViewController2 *contr2 = [[MyViewController2 alloc] initWithNibName:#"MyViewController2" bundle:nil];
[self.view addSubview:contr2.view];
now in the third uiview i want to return back on the first updating it ( calling viewDidLoad ). how can i do?
First of all - you are doing it wrong.
Since you are using view controllers present them modally or push them:
MyViewController2 *contr2 = [[MyViewController2 alloc] initWithNibName:#"MyViewController2" bundle:nil];
[self presentModalViewController:contr2];
If you want to dismiss modal controllers exactly to your root view controller you should obtain a pointer to it in the controller you are currently using and send it a message to dismiss every modal view that there is on it.
- (IBAction)doHomePage:(id)sender {
MyAppDelegate *appDelegate = (MyAppDelegate *)[UIApplication sharedApplication].delegate;
[appDelegate.navigationController.rootViewController dismissModalViewControllerAnimated:YES];
}
Also instead of viewDidLoad: you might want to use viewWillAppear: or viewDidAppear:.
Sorry beforehand if there are some typo errors in the code since I wrote it by hand.

How do I put information on the flipped side of the page?

How do I put information on the flipped side of the page ?
The "utility application" template in XCode creates a simple application with a main view and a flipside view; take a look at that to see and example of how the "horizontal flip" transition animation works.
Assuming you've defined a controller FlipsideViewController and your view is in a nib file named FlipsideView, you might do something like:
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:#"FlipsideView" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];

How to move from xib to xib

What is the better code to move from "page" to "page"?I have a questionnaire on 4 pages and I loading 4 views from 4 xibs.
I picked up 2 way of moving from xib to xib (in my case, from page to page).
Method 1:
-(IBAction) MaleTapped: (id) sender {
Page1M *ivc = [[Page1M alloc] init];
UINavigationController *nc = [[UINavigationController alloc]
initWithRootViewController:ivc];
[self presentModalViewController:nc animated:NO];
[ivc release];
[nc release];
}
Second way:
-(IBAction)GotoPage2M:(id)sender {
page2M = [ [Page2M alloc]
initWithNibName:#"Page2M" bundle:nil];
[self.view addSubview:page2M.view];}
One method uses the RootViewController method, the second just loads the subview. For my 4 pages, which is the better/cleaner/smarter way?
I would recommend using a UINavigationViewController in this way. Going several modal views deep is icky.
- (IBAction) goToNextPage:(id)sender {
UIViewController * newView = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
[self.navigationController pushViewController:newView animated:YES];
[newView release];
}
The only reason I might do subviews is for the extra transition options.
I would recommend checking out Apple's sample Page Control code. It shows how to create something that pages through multiple view controllers and load them dynamically from xibs. The example just loads the same xib several times, but you could replace it with code that loads a different view controller or xib for each page.