Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

oojustfakeoo

macrumors newbie
Original poster
Aug 11, 2011
2
0
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

Code:
    IBOutlet UIWindow *NewWindw;
    IBOutlet UIButton *NewButton;
Up Here i've declared the button and the new window.

ViewController.m

Code:
 -(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!
 
Last edited by a moderator:

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
It would be very unusual to use multiple windows under iOS. Stop coding for a moment and read the iOS Application Programming Guide so at least you're aiming for the right goal. Then read the iOS Human Interface Guidelines 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

macrumors regular
Aug 26, 2010
223
0
It would be very unusual to use multiple windows under iOS. Stop coding for a moment and read the iOS Application Programming Guide so at least you're aiming for the right goal. Then read the iOS Human Interface Guidelines 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

macrumors 6502
Jul 4, 2009
307
22
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

Code:
#import <UIKit/UIKit.h>

@interface ViewControllerOne : UIViewController {
    
}

-(IBAction)loadViewTwo:(id)sender;

@end

ViewControllerOne.m

Code:
#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

Code:
#import <UIKit/UIKit.h>

@interface ViewControllerTwo : UIViewController {
    
}

-(IBAction)loadViewOne:(id)sender;

@end

ViewControllerTwo.m

Code:
#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

macrumors newbie
Original poster
Aug 11, 2011
2
0
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

Code:
#import <UIKit/UIKit.h>

@interface ViewControllerOne : UIViewController {
    
}

-(IBAction)loadViewTwo:(id)sender;

@end

ViewControllerOne.m

Code:
#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

Code:
#import <UIKit/UIKit.h>

@interface ViewControllerTwo : UIViewController {
    
}

-(IBAction)loadViewOne:(id)sender;

@end

ViewControllerTwo.m

Code:
#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!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.