Passing and saving settings between FlipViewController from MainViewController - iphone

My FlipViewController has some setting in form of UISwitches for MainViewController. I am trying to set those settings (based on variables) when FlipViewController is loaded and save those settings when MainViewController is loaded back (from FlipView controller). Something is funky and i can't get it to work consistently.
It looks like when i call FlipViewController from MainViewController, FlipView is loaded before i can set the states of the switches in FlipView. How can i accomplish doing this?
Thanks in advance!
Vatsal
Function within MainViewController
// called when the user touches the info button
- (IBAction)showInfo
{
// create a new FlipsideViewController
FlipsideViewController *controller = [[FlipsideViewController alloc]
initWithNibName:#"FlipsideView" bundle:nil];
controller.delegate = self; // set the delegate
// set the animation style to a horizontal flip
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
// show the flipside of the app
[self presentModalViewController:controller animated:YES];
// set the controls on the flipside
[controller setSwitches]; // set each region's switch
//[controller setSelectedIndex:guessRows - 1]; // set number of choices
controller.wordsDatabase=self.wordsDatabase;
[controller release]; // release the controller FlipsideViewController
} // end method showInfo
Function setting up switches in FlipView Controller (Called in MainView controller)
-(void) setSwitches
{
}

Looks to me like your FlipSideViewController's setSwtiches method is called before you've assigned the controller a reference to the wordsDatabase.
ex:
[controller setSwitches];
controller.wordsDatabase=self.wordsDatabase;
should be:
controller.wordsDatabase=self.wordsDatabase;
[controller setSwitches];

Related

Initial screen auto fadeout to app

I am a master detail app which is embedded in tab bar controller. This loads from the beginning and works fine. Now, i want an initial page to load as soon as the app loads and then auto fade out to this screen without any event. How can i do the same? Please advice
You can add the initial viewController in the application:didFinishLaunchingWithOptions: method.
Present your initial controller ontop of the UINavigationController that holds the rootViewController (with no animation).
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:yourRootViewController];
self.window.rootViewController = navigationController;
UIInitialController *initialControlller = [[UIInitialController alloc] init];
initialControlller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
initialControlller.modalPresentationStyle = UIModalPresentationCurrentContext;
[navigationController presentViewController:initialControlller animated:NO completion:nil];
When you are ready to dismiss your initial you can do this (from the UIInitialController class) - with animation (you can set a NSTimer to call this method automatically):
[self dismissViewControllerAnimated:YES completion:nil];

How to load a navigation view created programmatically and make it a ModalView?

I'm making an iphone app out of the utility template in xcode. So in my FlispSideView I have a button that should show a custom image picker. I decided to use this nice one here link.
Now I made some changes cuz I'm not using a navigation controller to load the custom image picker (but rather modally) which is created programmatically inside the .m file. So I made the FlipSideView the delegate for the custom image picker but still lost when I come to loading the view. I created a xib file and tried to connect it to the image picker but that didn't work.
So I wonder what's the best way to do that?
I'm not sure I interpreted your question correctly, but based on the title, I think this might be what you are looking for:
// Initialize your custom controller and set the delegate
UIViewController *controller = [[UIViewController alloc] initWithNibName:#"MyView" bundle:nil];
controller.delegate = self;
// Set the title of your custom controller (optional)
controller.title = NSLocalizedString(#"My View", nil);
// Create a navigation controller with your custom controller as the root view controller
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:controller];
// Present the navigation controller as a modal view controller
[self.navigationController presentModalViewController:navCon animated:YES];
// Release objects you own
[navCon release];
[controller release];
If your image picker is a controller, and all the outlets on your xib are properly connected to it, this should work. You should be able to make your FlipSideView the delegate. Pressing cancel or done in the modal view should call a message in the delegate that says
[self.navigationController dismissModalViewControllerAnimated:YES];
EDIT:
Here is the first line of my example code updated to match the tutorial you are using:
CustomImagePicker *controller = [[CustomImagePicker alloc] init];
The rest is the same. You initialize a navigation controller with controller as the root view controller, then present the navigation controller as a modal view controller.
Creating navigation programatically
Use the code below to navigate programatically. Write the following code in
AppDelegate.m class
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
self.nav = [[UINavigationController alloc] initWithRootViewController:firstViewController];
[_window addSubview:nav.view];
[_window makeKeyAndVisible];
}

iPhone - unrecognized selector sent to instance - Trying to open the starting view after viewing several other views

I am just starting with iPhone programming. I used the utility application project template. A button on the main view of the utility application calls another view which shows some data. At the end of the presentation of the data a "end" view is shown. The "end" view contains a button to return to the main view. This all works great, however once you return to the mainview and try either to click the info button or click the button to call the data view the application terminates with the following error:
-[TheEVController startS]: unrecognized selector sent to instance 0x3933d90
EVController.m
- (IBAction)done {
EVController *controller = [[EV alloc] initWithNibName:#"MainView" bundle:nil]; //controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
MainViewController.m
- (IBAction)startS {
SVController *controller = [[SVController alloc] initWithNibName:#"SView" bundle:nil]; controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
Any suggestions?
If you want to call startS, which is a method on a MainViewController object, you can't call it on an EVController object.
[TheEVController startS];
tells the Objective-C runtime that you want to invoke the startS method in the TheEVController's class (or one of its parent classes).
It's not entirely clear from the code you posted (you didn't actually show us the section of code that is causing the exception) but from your description it sounds like you're overwriting a UIView variable that initially points to your MainViewController with a pointer to an EVController, and not resetting that variable when you show your MainViewController again.

Switching views - iPhone development

I need help figuring out how to change out the view in my application. I have a wonderfully working view that I have finished and now I'd like to be able to switch the view to a brand new, blank white screen to display.
I have these files:
HelloAppDelegate.h,
HelloAppDelegate.m,
HelloViewController.h, and
HelloViewController.m
Then, I added a new View Controller so now I have two more files:
SecondViewController.h and
SecondViewController.m
In my first view (HelloViewController), I have a button. When the user presses this button, I'd like SecondViewController to show up. So, in my HelloViewController.m, I have an action method
-(IBAction)switchToSecondView:(id)sender {
}
In this method, how can I go about initializing my second view and displaying it?
Thanks in advance!
If you want to do something like flipping view, making it modal and then returning back to the main view do following:
Define a delegate to indicate that secondary view finished its work
#protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish;
#end
In main view do following:
- (void)flipsideViewControllerDidFinish {
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction)showInfo {
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:#"FlipsideView" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
In secondary view do following:
- (IBAction)done {
[self.delegate flipsideViewControllerDidFinish];
}

How to use the 'setMyViewController' in iPhone'?

I want to ask a question about the iPhone application. In my program, there are several controller class. However, I dont' know how to handle them and switch the control right between different view controller classes. I read some code from the apple website. Can anyone explain to me? Thank you very much.
// I create a view controller called 'MyViewController'
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSLog(#"applicationDidFinishLaunching");
MyViewController *aViewController = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:[NSBundle mainBundle]]; // what meaning of this statement
[self setMyViewController:aViewController]; // can I set in other class
[aViewController release];
UIView *controllersView = [myViewController view]; // what is it use?
[window addSubview:controllersView];
// Override point for customization after application launch
[window makeKeyAndVisible];
}
// what meaning of this statement
MyViewController *aViewController = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:[NSBundle mainBundle]];
This block will load your main view controller from the .xib file. Do you know about Interface Builder, you can set the View of the ViewController in the MyViewController.xib and then load it using this line
[self setMyViewController:aViewController]; // can I set in other class
Theoretically, you can set a ViewController in anywhere you have viewControlelr as a property. However, the code here means that you set the aViewController as your root view controller in the program, the first view controller you will see when you open the program.
UIView *controllersView = [myViewController view]; // what is it use?
[window addSubview:controllersView];
These 2 lines will make the view visible and can be seen by the user. you add the subview of your root view controller into the main window, and then show it