简体   繁体   English

UIView - 与ViewDidLoad类似的方法?

[英]UIView - similar method to ViewDidLoad?

I'm creating an app that uses only Storyboard (no separate xib-s). 我正在创建一个仅使用Storyboard的应用程序(没有单独的xib-s)。 Here is a screenshot of how my storyboard looks: 以下是我的故事板外观的截图:

在此输入图像描述

Each of the three view controllers (one with "infinite" and "Levels" labels, one with two switches, and one with some label), is assigned correctly to .h and .m files. 三个视图控制器中的每一个(一个具有“无限”和“级别”标签,一个具有两个开关,一个具有一些标签)被正确分配给.h和.m文件。

And here's my issue - how to call something like ViewDidLoad or ViewWillAppear , or ViewDidAppear ? 这是我的问题 - 如何调用ViewDidLoadViewWillAppearViewDidAppear I tried to call -(void)willMoveToSuperview:(UIView *)newSuperview , but it doesn't work as viewDidLoad . 我试着调用-(void)willMoveToSuperview:(UIView *)newSuperview ,但它不能用作viewDidLoad

How to solve it? 怎么解决?


And, in OptionsController.m, I can't call any of viewDid... or viewWill... functions 并且,在OptionsController.m中,我无法调用viewDid ...或viewWill ...函数中的任何一个


In interface, I had heritance from UIView. 在界面中,我从UIView获得了遗产。 I changed it to UIViewController, and now I have all those methods, but now when I click on a button that should present "OptionsController", I get an error :[OptionsController _setViewDelegate:]: unrecognized selector sent to instance 0x8ab94e0'" – Artur Bartczak 1 hour ago delete 我把它更改为UIViewController,现在我已经拥有了所有这些方法,但现在当我点击一个应该显示“OptionsController”的按钮时,我收到一个错误:[OptionsController _setViewDelegate:]:无法识别的选择器发送到实例0x8ab94e0'“ - Artur Bartczak 1小时前删除

For each viewcontroller in your storyboard you have to add a .h and .m file to your project. 对于故事板中的每个视图控制器,您必须将.h和.m文件添加到项目中。 the name of the file is the class name you entered in the inspector in your storyboard for the viewcontroller. 文件名是您在viewcontroller的storyboard中的检查器中输入的类名。 so if you have a MainViewController of type UITableViewController you have to add the file via "new file" to your project. 因此,如果你有一个UITableViewController类型的MainViewController,你必须通过“新文件”将文件添加到你的项目中。 then in this files you call viewDidLoad and the other. 然后在这个文件中你调用viewDidLoad和另一个。

for your storyboard: select the first entry "ViewController". 为您的故事板:选择第一个条目“ViewController”。 in the inspector(right panel), under custom class enter a unique class name, OptionsViewController for example. 在检查器(右侧面板)中,在自定义类下输入一个唯一的类名,例如OptionsViewController。 then select the project panel(left panel), select the left icon for file browsing. 然后选择项目面板(左侧面板),选择左侧图标进行文件浏览。 right click and select "new file". 右键单击并选择“新文件”。 in the dialog select ios->cocoa touch->objective c class then next. 在对话框中选择ios-> cocoa touch-> objective c class然后接下来。 now enter exactly the same name as in storyboard under custom class. 现在输入与自定义类下的storyboard完全相同的名称。 for subclass select the parent class, if you drag a UIViewController in your storyboard, you have to enter here the same. 对于子类选择父类,如果在故事板中拖动UIViewController,则必须在此输入相同的内容。 next select the directory to save and click create. 然后选择要保存的目录,然后单击“创建”。

now if you click on the new created .m file you see the method viewDidLoad which you now can modify. 现在,如果单击新创建的.m文件,您将看到现在可以修改的viewDidLoad方法。

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

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