我有一个视图的项目。我正在通过程序绘制所有内容。所以,当我想另一个视图(屏幕)添加到项目中,我创建一个类从UIViewController类继承并实现方法Dynamiclly创建在iOS中查看
- (void)viewDidLoad
然后,我想从我原来查看加载这个视图,我这样做:
在ViewController.h
#import <UIKit/UIKit.h>
#import "TestViewControllerClass.h"
@interface ViewController : UIViewController <UITableViewDataSource> {
}
@property (strong,nonatomic) TestViewControllerClass *testView;
@end
在ViewController.m
@implementation ViewController
@synthesize testView;
- (void)viewDidLoad
{
[super viewDidLoad];
testView = [[TestViewControllerClass alloc] init];
[self.view addSubview:testView]; //crash here
}
然后在我的TestViewControllerClass.h
#import <UIKit/UIKit.h>
@interface TestViewControllerClass : UIViewController
@end
而且TestViewControllerClass.m
- (void)viewDidLoad
{
[super viewDidLoad];
}
要检查方法wiewDidLoad将被执行,我把有断点,但没有发生。事实上,我的应用程序崩溃(我把代码注释在哪里)。
当崩溃我接收:- [TestViewControllerClass上海华]:无法识别的选择发送到实例0x683aca0
哦,天啊!谢谢! – Kuba 2012-04-20 12:34:02