简体   繁体   English

使用Objc声明视图控制器?

[英]Declaring a View Controller with Objc?

如何用Objective C声明视图控制器?

Sorta depends. 排序取决于。 Just to give one example, let's say you have a new project setup using apple's "View based app" template. 仅举一个例子,假设您使用苹果公司的“基于视图的应用程序”模板进行了新的项目设置。 If you want to have a new view "slide up" and replace your current view you can do this. 如果您想使用新视图“向上滑动”并替换当前视图,则可以执行此操作。 Add a new file to you project of type 'UIViewController subclass', and select the 'With XIB for user interface' option. 将新文件添加到'UIViewController子类'类型的项目中,然后选择'用户界面带有XIB'选项。 Now, in you code, when you want to display this view do this: 现在,在您的代码中,当您想要显示此视图时,请执行以下操作:

MyViewController *myViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
[self presentModalViewController:myViewController animated:YES];
[myViewController release];

This is assuming that your new UIViewController subclass name is MyViewController and the the XIB is named MyViewController (so you should have MyViewController.c(.h)(.xib) 假设您的新UIViewController子类名称为MyViewController,而XIB名为MyViewController(因此您应该拥有MyViewController.c(.h)(。xib)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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