开发者

Problem With A Subview To Window Iphone sdk 4

开发者 https://www.devze.com 2023-01-07 12:47 出处:网络
The following code is in my \"switchviewcontroller.m\" file - (void)viewDidLoad { MainView *mainController=[[MainView alloc]

The following code is in my "switchviewcontroller.m" file

- (void)viewDidLoad {

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

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


    [super viewDidLoad];
}

All I am trying to do here is load this view "main" into the view in m开发者_JAVA百科y mainwindow.

The code just gives a warning and compiles, but when it executes it crashes on the line in warning

//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];


I believe you are trying to insert a UIViewController, not a UIView as insertSubview is expecting.

Try this:

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

精彩评论

暂无评论...
验证码 换一张
取 消