如何在Objective-C中调用方法? [英] How can I call a method in Objective-C?

查看:121
本文介绍了如何在Objective-C中调用方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个iPhone应用程序.我创建了一个
像这样的方法:

- (void)score {
    // some code
}

并且我试图用这样的其他方法调用它:

- (void)score2 {
    @selector(score);
}

但是它不起作用.那么,如何正确调用方法?

解决方案

要在这种情况下发送Objective-C消息,您可以这样做

[self score];

我建议您阅读Objective-C编程指南 《 Objective-C编程指南》

I am trying to build an iPhone app. I created a
method like this:

- (void)score {
    // some code
}

and I have tried to call it in an other method like this:

- (void)score2 {
    @selector(score);
}

But it does not work. So, how do I call a method correctly?

解决方案

To send an objective-c message in this instance you would do

[self score];

I suggest you read the Objective-C programming guide Objective-C Programming Guide

这篇关于如何在Objective-C中调用方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆