Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 11, 2011, 06:19 AM   #1
oojustfakeoo
macrumors newbie
 
Join Date: Aug 2011
Switch to a different Window - Cocoa Touch -

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 dejo; Aug 11, 2011 at 08:41 AM. Reason: Please use [code] tags.
oojustfakeoo is offline   0 Reply With Quote
Old Aug 11, 2011, 06:33 AM   #2
jiminaus
macrumors 65816
 
Join Date: Dec 2010
Location: 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.
jiminaus is offline   0 Reply With Quote
Old Aug 11, 2011, 08:39 AM   #3
Sykte
macrumors regular
 
Join Date: Aug 2010
Quote:
Originally Posted by jiminaus View Post
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.
__________________
Looking for apple/tech news on your IPhone or IPod touch, Try out PowerFeed. 100% free.
Sykte is offline   0 Reply With Quote
Old Aug 12, 2011, 12:08 AM   #4
ViviUO
macrumors 6502
 
Join Date: Jul 2009
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.
ViviUO is offline   0 Reply With Quote
Old Aug 14, 2011, 06:09 AM   #5
oojustfakeoo
Thread Starter
macrumors newbie
 
Join Date: Aug 2011
Quote:
Originally Posted by ViviUO View Post
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!
oojustfakeoo is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Cocoa Binding Controls to Parent Window? ArtOfWarfare Mac Programming 0 Oct 17, 2013 10:05 PM
Cocoa Touch and Objective C phalgun27 iPhone/iPad Programming 7 Aug 1, 2013 08:09 PM
Apps Switch but Active Window doesn't MacKenzie999 OS X 10.8 Mountain Lion 6 Nov 13, 2012 09:22 AM
Mac Mini - Switch Back to MAC window + XP Installations samacmini Windows, Linux & Others on the Mac 5 Nov 2, 2012 04:53 AM
Can I keep my # if I switch providers in the 30 day return window? zorinlynx iPhone 2 Sep 13, 2012 02:43 PM

Forum Jump

All times are GMT -5. The time now is 05:55 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC