PDA

View Full Version : Switch to a different Window - Cocoa Touch -




oojustfakeoo
Aug 11, 2011, 05:19 AM
i'm totally new to Objective-C and Cocoa Touch even if i have some basis of programming.

I would like to know how to set up an Action that behave like this.

When i press a button on the Main View, it opens a new window created before, then when i press a button on the 2nd window it switch back to the main one.
I just miss the instruction to switch between windows

ViewController.h

IBOutlet UIWindow *NewWindw;
IBOutlet UIButton *NewButton;

Up Here i've declared the button and the new window.

ViewController.m

-(IBAction) LaunchWindowsF: (id) sender{

**What here?**
}

Up Here i've declared the function that should load the new window, and connected it with the interface builder to the event TouchUpInside.

What's the code to launch the window NewWindw?

Thanks everyone!



jiminaus
Aug 11, 2011, 05:33 AM
It would be very unusual to use multiple windows under iOS. Stop coding for a moment and read the iOS Application Programming Guide (http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Introduction/Introduction.html) so at least you're aiming for the right goal. Then read the iOS Human Interface Guidelines (http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/Introduction/Introduction.html) so that you're design the right kind of UI for your app. iOS users expect their apps to behave a certain way which is philosophically different from desktop apps, and will quickly reject apps that don't meet their expectations.

Sykte
Aug 11, 2011, 07:39 AM
It would be very unusual to use multiple windows under iOS. Stop coding for a moment and read the iOS Application Programming Guide (http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Introduction/Introduction.html) so at least you're aiming for the right goal. Then read the iOS Human Interface Guidelines (http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/Introduction/Introduction.html) so that you're design the right kind of UI for your app. iOS users expect their apps to behave a certain way which is philosophically different from desktop apps, and will quickly reject apps that don't meet their expectations.


I would have to agree with Jiminaus. Understanding iOS paradigms will save you time in the long run. Yes, creating your first app is exciting but having a good foundation will keep you interested in app making. Otherwise you will become frustated and possibly give up.

ViviUO
Aug 11, 2011, 11:08 PM
You don't want to load a new window. You want to load a new view controller. I would do something like this:

ViewControllerOne.h


#import <UIKit/UIKit.h>

@interface ViewControllerOne : UIViewController {

}

-(IBAction)loadViewTwo:(id)sender;

@end


ViewControllerOne.m


#import "ViewControllerOne.h"
#import "ViewControllerTwo.h"

@implementation ViewControllerOne

-(IBAction)loadViewTwo:(id)sender {
ViewControllerTwo *viewTwo = [[ViewControllerTwo alloc] initWithNibName:@"ViewControllerTwo" bundle:nil];

[self.view addSubview:viewTwo.view];
}


ViewControllerTwo.h


#import <UIKit/UIKit.h>

@interface ViewControllerTwo : UIViewController {

}

-(IBAction)loadViewOne:(id)sender;

@end


ViewControllerTwo.m


#import "ViewControllerTwo.h"
#import "ViewControllerOne.h"


@implementation ViewControllerTwo

-(IBAction)loadViewOne:(id)sender {
ViewControllerOne *viewOne = [[ViewControllerOne alloc] initWithNibName:@"ViewControllerOne" bundle:nil];

[self.view addSubview:viewOne.view];
}


By allocating and initializing a new view controller via code, you remove several steps from interface builder. All you have to do in interface builder is connect your buttons to the correct IBActions by control click + dragging to file's owner.

You could also do it modally.

oojustfakeoo
Aug 14, 2011, 05:09 AM
You don't want to load a new window. You want to load a new view controller. I would do something like this:

ViewControllerOne.h


#import <UIKit/UIKit.h>

@interface ViewControllerOne : UIViewController {

}

-(IBAction)loadViewTwo:(id)sender;

@end


ViewControllerOne.m


#import "ViewControllerOne.h"
#import "ViewControllerTwo.h"

@implementation ViewControllerOne

-(IBAction)loadViewTwo:(id)sender {
ViewControllerTwo *viewTwo = [[ViewControllerTwo alloc] initWithNibName:@"ViewControllerTwo" bundle:nil];

[self.view addSubview:viewTwo.view];
}


ViewControllerTwo.h


#import <UIKit/UIKit.h>

@interface ViewControllerTwo : UIViewController {

}

-(IBAction)loadViewOne:(id)sender;

@end


ViewControllerTwo.m


#import "ViewControllerTwo.h"
#import "ViewControllerOne.h"


@implementation ViewControllerTwo

-(IBAction)loadViewOne:(id)sender {
ViewControllerOne *viewOne = [[ViewControllerOne alloc] initWithNibName:@"ViewControllerOne" bundle:nil];

[self.view addSubview:viewOne.view];
}


By allocating and initializing a new view controller via code, you remove several steps from interface builder. All you have to do in interface builder is connect your buttons to the correct IBActions by control click + dragging to file's owner.

You could also do it modally.

Thank you very much, that's exactly what i meant! :)
I'll try to do so, and let you know!