我有一個視圖的項目。我正在通過程序繪製所有內容。所以,當我想另一個視圖(屏幕)添加到項目中,我創建一個類從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