0

iPhoneアプリのビューコントローラー間でビューを切り替えようとしていますが、クラッシュしました。基本的に、mainScreenからtestに切り替えています。

デバッガーでエラーが発生します:

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)

mainscreen.h

#import <UIKit/UIKit.h>

@interface MainScreen : UIViewController {

}

-(IBAction)btnFirstPage:(id)sender;

@end

mainscreen.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. */

test.h

#import <UIKit/UIKit.h>

@interface test : UIViewController {
}

@end
4

2 に答える 2

1

これは奇妙に見えます:test1 = [[test1 alloc] ...]。メッセージを変数に送信allocしていますが、これは最初はnullポインターであると想定しているため、静かに無視されています。allocそれ自体ではなく、test1のクラスタイプで呼び出す必要がありtest1ます。

于 2010-05-31T10:12:54.847 に答える
0

test1 = [[test alloc] initWithNibName:@ "test" undle:nil]; //ここではテストする必要があります。test1ではありません

クラスからオブジェクトを作成するときは、NSObjectクラスで使用するallocおよびallocWithZone静的メソッドを使用する必要があります。したがって、クラス名を使用する必要があります。変数名ではありません。(test1)

于 2010-05-31T15:46:13.123 に答える