从按钮运行类 viewDidLoad 方法

发布于 2024-12-25 05:26:03 字数 86 浏览 7 评论 0原文

我想知道如何从另一个类加载 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁吢 2025-01-01 05:26:03

你需要更精确。

你正在操纵什么样的类? UIViewControllers

如果是这样,您可以 alloc/init (或者 alloc/initWithNibName 如果您使用 Interface Builder)当您按下按钮时查看控制器。 viewDidLoad 方法将在第二个视图控制器的视图被加载时调用(不一定是在分配 viewController 时,而是在第一个视图控制器显示视图时)时间)。

如果您需要在每次按下按钮时执行 viewDidLoad 方法中的代码,请优先使用 viewWillAppearviewDidAppear 方法。

You need to be more precise.

What kind of classes are you manipulating ? UIViewControllers ?

If so, you can alloc/init (or alloc/initWithNibName if you are using Interface Builder) the second ViewController when your button is pushed. The viewDidLoad method will be called when the view of the second view controller will be loaded (not necessarily when the viewController 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 the viewWillAppear or viewDidAppear methods.

晚风撩人 2025-01-01 05:26:03

如果您谈论的是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文