2010-07-12 41 views
0

下面的代碼是在我的「switchviewcontroller.m」文件問題,一個子視圖窗口iPhone SDK的4

- (void)viewDidLoad { 

    MainView *mainController=[[MainView alloc] 
             initWithNibName:@"Blue View" bundle:nil]; 

    self.mainViewController=mainController; 
    [self.view insertSubview: mainController atIndex:0]; 
    [mainController release]; 


    [super viewDidLoad]; 
} 

所有我想在這裏做的就是這一觀點的「主」加載到視圖中的我主窗口。

代碼只是給出了一個警告,編譯,但在執行時它警告

//80: warning: incompatible Objective-C types 'struct MainView *', expected 'struct UIView *' when //passing argument 1 of 'insertSubview:atIndex:' from distinct Objective-C type 
[self.view insertSubview: mainController atIndex:0]; 

回答

1

崩潰就行了,我相信你想插入UIViewController,而不是作爲UIViewinsertSubview期待。

試試這個:

[self.view insertSubview: mainController.view atIndex:0];