切换视图控制器崩溃,无人例外
-
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)
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
解决方案
这看起来很奇怪: test1 = [[test1 alloc] ...]
. 。您正在发送 alloc
给变量的消息,我认为该变量最初是空指针,因此被悄悄地忽略了。你应该调用 alloc
上 test1
的类型,不是 test1
本身。
其他提示
test1 = [[test alloc] initwithnibname:@“ test” undle:nil]; //这里必须进行测试。不是测试1
当您从类创建对象时,您必须在NSOBJECT类中使用Alloc和Allocwithzone静态方法。因此,您必须使用班级名称。不是变量名。(test1)
不隶属于 StackOverflow