如何解决基本视图切换代码使iPhone模拟器崩溃
|| 我一直在尝试从两个单独的视图控制器切换两个视图,但是它永远无法正常工作,模拟器总是崩溃到主屏幕。我正在使用Xcode 3.2.5,这是我的代码- 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];
}
在界面生成器中,我所做的所有工作都是链接文件的所有者类和按钮。还使SwitchViewsViewController首先加载,而不是MainWindow。一切都建立了,但是当我尝试运行该应用程序时,它崩溃并发送到主屏幕。谁能帮我这个?
解决方法
当您以笔尖名称nil分配您的secondViewController初始化时,它实际上应该是您的笔尖文件的名称。
SecondViewController * screen = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
另外,您应该合上括号;-)
, XIB错误很少在编译时发现。因此,当您说以
SwitchViewsViewController
作为应用程序的起点时,我假设您已更改Info.plist
中的主笔尖文件。通常,该nib文件负责提供有关应用程序委托的信息。因此,如果您将其更改为SwitchViewsViewController
,这是一个非常糟糕的主意。我建议您将MainWindow.xib
放回去。我认为这要容易一些,但是如果您对编程有兴趣,可以看看this post
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。