視野コントローラーの切り替えは、無作法な例外を除いてクラッシュします
-
05-10-2019 - |
質問
iPhoneアプリのビューコントローラー間のビューを切り替えようとしていますが、クラッシュしました。基本的に、私はメインスクリーンからテストに切り替えています。
デバッガーでエラーが発生します:
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)
メインスクリーン
#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
解決
これは奇妙に見えます: test1 = [[test1 alloc] ...]
. 。あなたはを送っています alloc
変数へのメッセージ。これは最初はヌルポインターであるため、静かに無視されていると思います。呼び出すべきです alloc
の上 test1
'のクラスタイプではありません test1
自体。
他のヒント
test1 = [[test alloc] initwithnibname:@"test" undle:nil]; //ここでは、テストする必要があります。 test1ではありません
クラスからオブジェクトを作成する場合、nSObjectクラスで使用されるallocおよびallocwithzoneの静的メソッドを使用する必要があります。したがって、クラス名を使用する必要があります。変数名ではありません。(test1)
所属していません StackOverflow