How to load an XIB?

前端 未结 3 1354
伪装坚强ぢ
伪装坚强ぢ 2020-12-14 12:33

I have an app with 2 screens (MainViewController and AboutViewController). Upon the user clicking a button, I\'d like to load the AboutViewController screen, which is defin

3条回答
  •  一个人的身影
    2020-12-14 12:38

    With an About screen you probably just want to show a view and then dismiss it. So rather than use a whole new view controller you can just cover the current view.

    Assuming you have an ivar

    UIView *aboutUsView;
    

    with the appropriate property.

    In your view controller do:

    [[NSBundle mainBundle] loadNibNamed:@"AboutUsView" owner:self options:nil]; // Retains top level items
    [self.view addSubview:aboutUsView];  // Retains the view
    [aboutUsView release];
    

    To remove the view, say in an action connected to a button on the view, do:

    [aboutUsView removeFromSuperview], aboutUsView = nil;  // Releases the view
    

提交回复
热议问题