简体   繁体   中英

Presenting a view controller that doesn't have a nib file

How would I go about presenting a view controller that doesn't have a nib file?

I have a viewController without a nib and would like to have this view displayed when a user touches a button. Is it necessary to also have a nib file to do this?

thanks for any help.

I ended up using:

CameraViewController *cvc = [[CameraViewController alloc] init];
        [self.navigationController pushViewController:cvc animated:YES];
        [cvc release];

You don't need a nib for a view controller. In general, it can be useful to have a nib because of maintenance and other things; but if you don't want a nib you'll want to override the -loadView method provided by UIViewController .

You can create the view programmatically instead of inside of the nib. Then a nib would not be needed.

- (IBAction)buttonPressed:(id)sender {
CameraViewController *cameraViewController = [[CameraViewController alloc] init];
[self presentModalViewController:cameraViewController animated:YES];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM