开发者

Basic View Switch Code Crashes iPhone simulator

I've been trying to switch two views from two separate view controllers for a while and it never works, the simulator always crashes to the home screen. I'm using Xcode 3.2.5 and this is my code -

SwitchViewsViewController.h

#import <UIKit/UIKit.h>
#import "SecondViewController.h"

@interface SwitchViewsViewController : UIViewController {
}
-(IBAction)pushButton;
@end

SwitchViewsViewController.m

#import "SwitchViewsViewController.h"
#import "SecondViewController.h"开发者_开发知识库

@implementation SwitchViewsViewController

-(IBAction)pushButton {
    SecondViewController *screen = [[SecondViewController alloc] initWithNibName:nil bundle:nil    
    screen.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentModalViewController:screen animated:YES]
    [screen release];
}

SecondViewController.h

#import <UIKit/UIKit.h>

@interface SecondViewController : UIViewController {
}
-(IBAction)pushBack;
@end

SecondViewController.m

#import "SecondViewController.h"

@implementation SecondViewController

-(IBAction)pushBack{
    [self dismissModalViewControllerAnimated:YES];
}

In interface builder, all i've done is linked the file's owner classes and the buttons. Also made the SwitchViewsViewController load first, and not MainWindow. Everything builds but when I try to run the app it crashes and sends it to the home screen. Can anyone help me with this?


When you alloc your secondViewController you init with nib name nil, this should actually be the name of your nib file.

SecondViewController *screen = [[SecondViewController alloc] initWithNibName:nil bundle:nil];

Also, you should close your brackets ;-)


XIB errors are rarely uncovered at compile time. So when you say you made SwitchViewsViewController the starting point of the app, I am assuming that you have altered the main nib file in Info.plist. Usually that nib file is responsible for providing information about the application delegate. So it's a pretty bad idea if you've changed it to SwitchViewsViewController. I suggest you incorporate the MainWindow.xib back. This is easier I think but if you are interested in doing programmatically than take a look at this post.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜