Subscribe ( )

iPhone Programming Tutorials

 

Forum

You must be logged in to post Login Register

Search 

more than 1 view

User Post

2:43 am
October 8, 2008


thathoo

Noob

posts 1

1

hi brandon,

first - awesome job with the site!

i am trying to create an app with more than 1 view and have a situation where in with 1 button tap on view1 - the user should be able to fade into view2..sorta like the example viewtransition on apple.com - but i need objects like buttons and stuff on each view which are going to be different in each view…

so i created 2 view controllers and in the appdelegate file inside applicationDidFinishLaunching i have:

    MyViewController *aViewController = [[MyViewController alloc]
                                         initWithNibName:@”ControllerView” bundle:[NSBundle mainBundle]];
    self.myViewController = aViewController;
    [aViewController release];
   
    SecondViewController *yaViewController = [[SecondViewController alloc]
                                              initWithNibName:@”YaView” bundle:[NSBundle mainBundle]];
    self.mySecondViewController = yaViewController;
    [yaViewController release];
   
    // setup the view
    UIView *controllersView = [myViewController view];
    [window addSubview:controllersView];
   
    UIView *var = [mySecondViewController view];
    [window addSubview:var];

   [window makeKeyAndVisible];

but of course this gives me errors - what do u think is the way i should go about this…

2:43 pm
October 8, 2008


VertigoSol

Moderator

posts 17

2

Yoiur best way to do things in a heirarchy structure such as
UIWindow
|
View
| |
subview subview
You can only have one view on the screen at a time but you can add subviews to that view. You would want to do something like this

MyViewController *aViewController = [[MyViewController alloc]
initWithNibName:@”ControllerView” bundle:[NSBundle mainBundle]];
self.myViewController = aViewController;
[aViewController release];

SecondViewController *yaViewController = [[SecondViewController alloc]

initWithNibName:@”YaView” bundle:[NSBundle mainBundle]];
self.mySecondViewController = yaViewController;
[yaViewController release];

// make a view the whole screen wide
UIView *mainView = [[UIView alloc] initWithFrame[[UIScreen mainScreen] bounds]

//add both the view to the main view
[mainView addSubview:aViewController.view];
[mainView addSubview:yaViewController.view]

//add the view to the window
[window addSubview:mainView];

This may not be syntactically correct but the concept is


About the iCodeBlog forum

Currently Online:

2 Guests

Maximum Online: 14

Forums:

Groups: 2

Forums: 6

Topics: 129

Posts: 435

Members:

There are 239 members

There are 1 guests


Brandon has made 75 posts

Top Posters:

bobcubsfan - 43

crazyiez - 30

Uhu - 17

VertigoSol - 17

Nick - 15

Administrator: Brandon | Moderators: VertigoSol


© - Version 3.1.4 (Build 357)  

Share and Enjoy: