0

我试图在我的 iPhone 应用程序中的视图控制器之间切换视图,但它崩溃了。基本上我正在从 mainScreen 切换到测试。

我在调试器中收到错误:

0x01d6a000  <+0000>  push   %ebp
0x01d6a001  <+0001>  mov    %esp,%ebp
0x01d6a003  <+0003>  int3   
0x01d6a004  <+0004>  leave  (HIGHLIGHTED)
0x01d6a005  <+0005>  ret    
0x01d6a006  <+0006>  nopw   %cs:0x0(%eax,%eax,1)

主屏幕.h

#import <UIKit/UIKit.h>

@interface MainScreen : UIViewController {

}

-(IBAction)btnFirstPage:(id)sender;

@end

主屏幕.m

#import "MainScreen.h"
#import "test.h"

@implementation MainScreen

-(IBAction)btnFirstPage:(id)sender{

 test1 = [[test1 alloc] 

    initWithNibName:@"test"  (test may not respond to -alloc)

    bundle:nil];

    [self.view addSubview:test1.view];

/* etc. */

测试.h

#import <UIKit/UIKit.h>

@interface test : UIViewController {
}

@end
4

2 回答 2

1

这看起来很奇怪:test1 = [[test1 alloc] ...]. 您正在将alloc消息发送到一个变量,我假设它最初是空指针,因此被悄悄地忽略了。您应该调用allocontest1的类类型,而不是test1它本身。

于 2010-05-31T10:12:54.847 回答
0

test1 = [[test alloc] initWithNibName:@"test" undle:nil]; //这里必须是测试。不测试1

当您从类创建对象时,您必须使用 NSObject 类中的 alloc 和 allocWithZone 静态方法。所以你必须使用类名。不是变量名。(test1)

于 2010-05-31T15:46:13.123 回答