Subscribe ( )

iPhone Programming Tutorials


 

Forum

You must be logged in to post Login Register

Search 

Application Won’t Switch Views??

User Post

10:18 am
November 3, 2008


bitwise

Noob

bitwise

posts 2

1

I created a View-Based Application in XCode. On the main view there is a UIButton. Then I created a second view called View2.xib which has the UILabel that says “Second View”.

Now, all I want to do is display the second view when you click on the button. In the view controller class for the first view that contains the button I added.

#import View2ViewController.h

View2ViewController *View2;

And I added the property for this. This class also has the IBAction for the button click event, which works just fine and executes when clicked. Now, in the .m file I obviously @synthesize View2; and begin to edit the button click method to display the view. Here is the code:

if(self.View2 == nil) {
        View2ViewController *two = [[View2ViewController alloc] initWithNibName:@”View2″ bundle:[NSBundle mainBundle]];
        self.View2 = two;
        [two release];

}
    [self.navigationController pushViewController:self.View2 animated:YES];

Everything complies, and runs. When I click on the button the application does NOT display the second view. Nothing crashes, but it doesn't display the view. What am I doing wrong. I have everything linked up in Interface Builder. It's quite basic.

Is a “View-Based Application” not the correct type for doing this? Thanks everyone.

11:29 am
November 18, 2008


VertigoSol

Moderator

posts 26

2

probably better not to store the view locally just do

View2ViewController *two = [[View2ViewController alloc] initWithNibName:@”View2″ bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:two animated:YES];
[two release]

just relialized your probably releasing the view before it is being pushed on the stack

e^i -1 =0

9:22 pm
January 6, 2009


Skippie

Noob

posts 1

3

I am having the exact same problem, when I create a view based application, the code does not work.  When I create a a navigation based app, everything works fine.  I have looked at the code side by side and I cannot figure what is wrong.  Anyone have the solution?

10:05 pm
January 9, 2009


sandeepiphone

Noob

posts 1

4

I have also same type of problem.i try my best but couldt not get success so far,plz if any body know abt it how it resolve give me solution,thanks its work fine with navigation based app but not with two simple view where first view contain button for luanching second view.

8:21 pm
February 16, 2009


rob345

Noob

posts 5

5

I am looking for the same answer.  Why is this such a difficult thing to do?  I have two views and cooresponding controllers..and the rootViewController files.

HomePageView.xib, HomePageViewController.h and .m

EssentialsPageView.xib, EssentialsPageViewController.h and .m

I have a button on HomePage and of course the rootViewController class displays this page just fine by enacting the 'viewDidLoad' method….

- (void)viewDidLoad
{
    HomePageViewController *viewController = [[HomePageViewController alloc]
                                              initWithNibName:@”HomePageView” bundle:nil];
    self.homeViewController = viewController;
    [viewController release];
    [self.view insertSubview:homeViewController.view atIndex:1];
 }


  I also tested the following code on the file HomePageViewController.m …

-(IBAction) essentialsButton
{
    NSLog(@”essentials button pressed”);
    RootViewController *go = [[RootViewController alloc] init];
    go.loadEssentialsView;
    [go release];
    }

and it fires the following method on the rootViewController.m file…..

-(void) loadEssentialsView
{
        NSLog(@”loadEssentialsView method is firing”);
        EssentialsViewController *thisviewController = [[EssentialsViewController alloc]
                                                initWithNibName:@”EssentialsPageView” bundle:nil];
        self.essentialsViewController = thisviewController;
        [thisviewController release];
        [self.view insertSubview: essentialsViewController.view atIndex:2];
        [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:2];
 }

Please remember that RootViewController is an subclass of UIViewController, not UINaviagationController.I don't want to use a navigation controller because of the viewing requirements.

I can only think there must be some conflict with the HomeView that is already loaded.  I know I can't use a 'removeFromSuperView' method while the view is being displayed.  Is there a problem with 'insertSubView'???  I am so confused….

8:25 pm
February 16, 2009


rob345

Noob

posts 5

6

To add some clarity to the last post….  the above code builds and runs fine, but the HomePageView does not change.  Perhaps 'insertSubView' or exchangeSubViewAtIndex' is not correct, but I have tried all the applicable methods of the UIView class and nothing seems to work.

Thanks…

Search 

About the iCodeBlog forum

Most Users Ever Online:

44


Currently Online:

7 Guests

Forum Stats:

Groups: 2

Forums: 6

Topics: 419

Posts: 893

Membership:

There are 934 Members

There has been 1 Guest

There are 2 Admins

There is 1 Moderator

Top Posters:

bobcubsfan – 54

crazyiez – 30

Uhu – 17

AdeC – 17

Nick – 15

jitesh61 – 12

Administrators: Brandon (88 Posts), Collin (0 Posts)

Moderators: VertigoSol (26 Posts)



©   

  • Posted by on 6 Aug 2008 in Uncategorized
  •   |  
  •   |  
  •   |  
  • Comments Off

Comments are closed.