Possible Duplicate:
UIAlertView crashes when added to app第二屏幕中的標籤欄控制器
我是Objective-C和Xcode的新手。在我的應用程序中,第一個屏幕是一個視圖控制器和一個按鈕。當我按下該按鈕時,我想顯示標籤欄,因此標籤欄將成爲第二個屏幕。
這裏就是我想要做的事:
appdelegate.h
@property (strong, nonatomic) FirstViewController *viewController1;
appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController1 = [[FirstViewController alloc]
initWithNibName:@"FirstViewController" bundle:nil];
self.window.rootViewController = self.viewController1;
[self.window makeKeyAndVisible];
return YES; }
在我FirsViewController.m
有事件按鈕點擊:
-(IBAction) showMainView:(id) sender{
ViewController *mainViewController = [[ViewController alloc] initWithNibName:@"ViewController"
bundle:nil];
[self.view addSubview:mainViewController.view];
mainViewController = [[ViewController alloc] initWithNibName:@"ViewController"
bundle:nil];
[self.view addSubview:mainViewController.view];
ViewController是一個帶有標籤欄的xib。
在IB的第二個xib文件中,我爲「文件所有者」和AppDelegate - appdelegate類選擇了UIApplication類。然後我加入了文件所有者與應用程序代理。
當我運行我的應用程序,並單擊按鈕上我的第一個觀點,應用程序崩潰,出現以下錯誤: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ViewController 0x744f0f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key delegate.'
你能告訴我怎樣才能解決這個問題?可能是單擊按鈕後,我應該重新分配tabbarController爲rootViewController
? 謝謝。
你是否創建'mainViewController'兩次?你的代碼看起來像那樣。 – iDev