调用带有参数的OBJ-C方法 [英] Calling a obj-c method with a parameter

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

问题描述

我已经改变C风格的功能,一个Objective-C的方法。作为一种方法,我如何使用它?

I've change a c-style function to an objective-c method. As a method, how do i use it?

    NSString* myfunc( int x )

       is now:

    - (NSString *)myFuncWithParam:(int)x


 c code:  myString = myfunc(x);  // works

 obj-c code: myString = myFuncWithParam(x); // fails to compile.

这是其中一个答案:myString的= [对象myFuncWithParam:X];

From one of the answers: myString = [object myFuncWithParam:x];

在这种情况下,你会对象是什么?

In that case, what would "object" be?

推荐答案

的myString = [对象myFuncWithParam:X];

如果对象是具有你调用方法的对象。如果你从同一个对象调用它,你会用'自我'。 这tutoria 升可能会帮助你学习的OBJ-C。

Where object is the object which has the method you're calling. If you're calling it from the same object, you'll use 'self'. This tutorial might help you out in learning Obj-C.

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

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