UIViewController类中的presentModalViewController

Gar*_*ary 1 iphone cocoa-touch objective-c uiviewcontroller ios

View *view1 = [[View alloc] init];  
[self presentModalViewController:view1 animated:YES];
Run Code Online (Sandbox Code Playgroud)

上面的代码在连接到a时有效UIButton.通过将应用程序放入viewDidLoad:方法中,它无法在启动应用程序时起作用.我希望在发布时运行它.

Sha*_*rog 5

仔细查看您正在调用的方法:presentModalViewController:显示控制器,而不是视图.

正确的模式是这样的:

MyViewController* myViewController = [[MyViewController alloc] initWithNibName:@"MyView" bundle:nil];
[self presentModalViewController:myViewController animated:YES];
[myViewController release];
Run Code Online (Sandbox Code Playgroud)