从按钮运行类 viewDidLoad 方法
我想知道如何从另一个类加载 Objective-C 中的类?我有一个按钮,当用户按下这个按钮时,我希望它启动另一个类(调用它的 viewDidLoad 方法)
I was wondering how can you load a class in objective-c from another class? I have a push action button in one and when the users presses this I want it to start this other Class (calling its viewDidLoad method)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你需要更精确。
你正在操纵什么样的类?
UIViewControllers
?如果是这样,您可以
alloc
/init
(或者alloc
/initWithNibName
如果您使用 Interface Builder)当您按下按钮时查看控制器。viewDidLoad
方法将在第二个视图控制器的视图被加载时调用(不一定是在分配viewController
时,而是在第一个视图控制器显示视图时)时间)。如果您需要在每次按下按钮时执行
viewDidLoad
方法中的代码,请优先使用viewWillAppear
或viewDidAppear
方法。You need to be more precise.
What kind of classes are you manipulating ?
UIViewControllers
?If so, you can
alloc
/init
(oralloc
/initWithNibName
if you are using Interface Builder) the second ViewController when your button is pushed. TheviewDidLoad
method will be called when the view of the second view controller will be loaded (not necessarily when theviewController
is allocated, but when the view will be displayed for the first time).If you need the execute the code in the
viewDidLoad
method every time the button is pushed, prefere using theviewWillAppear
orviewDidAppear
methods.如果您谈论的是 UIViewController 子类的类,那么您可以通过将另一个视图控制器的视图推入导航控制器对象来加载它。您还可以在第一个控制器视图上添加第二个控制器的视图。
If you are talking about the classes which are subclass of
UIViewController
then you can load view of another view controller by pushing it into the navigation controller object. Also you can add the view of the second controller on the first controller view.