【问题标题】:Basic View Switch Code Crashes iPhone simulator基本视图切换代码崩溃 iPhone 模拟器
【发布时间】:2011-06-23 23:18:01
【问题描述】:

一段时间以来,我一直在尝试从两个单独的视图控制器切换两个视图,但始终无法正常工作,模拟器总是崩溃到主屏幕。我正在使用 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。一切都建立了,但是当我尝试运行应用程序时,它崩溃并将其发送到主屏幕。谁能帮我解决这个问题?

【问题讨论】:

    标签: iphone xcode sdk


    【解决方案1】:

    当您使用 nib 名称 nil 分配您的 secondViewController 时,这实际上应该是您的 nib 文件的名称。

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

    另外,你应该关闭你的括号;-)

    【讨论】:

    • 等一下,当你按下按钮时,应用程序会崩溃,还是在启动时崩溃?
    • 按钮崩溃但我已修复,视图未链接到文件所有者
    【解决方案2】:

    XIB 错误很少在编译时被发现。因此,当您说您将SwitchViewsViewController 作为应用程序的起点时,我假设您已经更改了Info.plist 中的主nib 文件。通常,该 nib 文件负责提供有关应用程序委托的信息。因此,如果您已将其更改为 SwitchViewsViewController,这是一个非常糟糕的主意。我建议您将MainWindow.xib 合并到后面。我认为这更容易,但如果您有兴趣以编程方式进行操作,请查看this post

    【讨论】:

    • 我修好了,视图不在 secondviewcontroller 上,没有链接到文件所有者。感谢您的帮助!
    猜你喜欢
    • 2011-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-11
    • 1970-01-01
    • 2011-07-02
    • 2012-01-04
    • 1970-01-01
    相关资源
    最近更新 更多