Objective-C:如何调用实例方法

时间:2022-04-08 19:51:08

I need to call a method I have defined as:

我需要调用我定义为:

-(IBAction)next:(id)sender{ 
...

}

I want to call it in -[UIViewController viewDidload]

我想调用-[UIViewController viewDidload]

How can I call this method programmatically?

如何以编程方式调用此方法?

1 个解决方案

#1


7  

[self next:nil];
  • self is the object receiving the message, assuming -next: is defined in the same class as -viewDidLoad.
  • self是接收消息的对象,假设-next:与-viewDidLoad在同一个类中定义。
  • next: is the name of the message (method).
  • 接下来:是消息(方法)的名称。
  • Since you don't use sender, pass the argument nil, meaning "nothing".
  • 因为不使用sender,所以传递参数nil,意思是“没有”。

If -next: is defined in the App delegate but -viewDidLoad in some view controller, use

If -next:在App委托中定义,但是-viewDidLoad在某些视图控制器中,请使用

[UIApplication sharedApplication].delegate

to refer to the app delegate. So the statement becomes

引用app委托。所以语句变成了

[[UIApplication sharedApplication].delegate next:nil];

#1


7  

[self next:nil];
  • self is the object receiving the message, assuming -next: is defined in the same class as -viewDidLoad.
  • self是接收消息的对象,假设-next:与-viewDidLoad在同一个类中定义。
  • next: is the name of the message (method).
  • 接下来:是消息(方法)的名称。
  • Since you don't use sender, pass the argument nil, meaning "nothing".
  • 因为不使用sender,所以传递参数nil,意思是“没有”。

If -next: is defined in the App delegate but -viewDidLoad in some view controller, use

If -next:在App委托中定义,但是-viewDidLoad在某些视图控制器中,请使用

[UIApplication sharedApplication].delegate

to refer to the app delegate. So the statement becomes

引用app委托。所以语句变成了

[[UIApplication sharedApplication].delegate next:nil];