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)
我想知道如何从另一个类加载Objective-c中的类?我有一个推送操作按钮,当用户按下这个按钮时,我希望它启动另一个类(调用它的viewDidLoad方法)
2 个解决方案
#1
1
You need to be more precise.
你需要更精确。
What kind of classes are you manipulating ? UIViewControllers
?
你在操什么类? 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).
如果是这样,您可以在按下按钮时为第二个ViewController分配/ init(或者如果使用Interface Builder则为alloc / initWithNibName)。当加载第二个视图控制器的视图时,将调用viewDidLoad方法(不一定在分配viewController时,但是第一次显示视图时)。
If you need the execute the code in the viewDidLoad
method every time the button is pushed, prefere using the viewWillAppear
or viewDidAppear
methods.
如果需要在每次按下按钮时执行viewDidLoad方法中的代码,请优先使用viewWillAppear或viewDidAppear方法。
#2
0
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.
如果您正在讨论作为UIViewController的子类的类,那么您可以通过将其推入导航控制器对象来加载另一个视图控制器的视图。您还可以在第一个控制器视图上添加第二个控制器的视图。
#1
1
You need to be more precise.
你需要更精确。
What kind of classes are you manipulating ? UIViewControllers
?
你在操什么类? 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).
如果是这样,您可以在按下按钮时为第二个ViewController分配/ init(或者如果使用Interface Builder则为alloc / initWithNibName)。当加载第二个视图控制器的视图时,将调用viewDidLoad方法(不一定在分配viewController时,但是第一次显示视图时)。
If you need the execute the code in the viewDidLoad
method every time the button is pushed, prefere using the viewWillAppear
or viewDidAppear
methods.
如果需要在每次按下按钮时执行viewDidLoad方法中的代码,请优先使用viewWillAppear或viewDidAppear方法。
#2
0
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.
如果您正在讨论作为UIViewController的子类的类,那么您可以通过将其推入导航控制器对象来加载另一个视图控制器的视图。您还可以在第一个控制器视图上添加第二个控制器的视图。