如何从Objective C中的另一种方法调用方法?
答
你得到一个指针到实现其他方法的对象,并发送相应信息(如[otherObject doSomething]
)。
+1
请更清楚查克我dint让你 – 2010-10-12 04:10:53
答
用于调用对象的方法的基本语法是这样的:
[object method];
[object methodWithInput:input];
如果方法返回值:
output = [object methodWithOutput];
output = [object methodWithInputAndOutput:input];
编辑:
这里是一个很好的例子,如何从其他类调用方法:
OBJECTIVE C - Objective-C call method on another class?
例子:
SomeClass* object = [[SomeClass alloc] init]; // Create an instance of SomeClass
[object someMethod]; // Send the someMethod message
+0
感谢naveed它帮助! – 2010-10-12 04:18:11
答
例如:
@implementation view1
(void)someMethod
{
......code of method...
}
@implementation view2
(void)fistMethod
{
view1 *abc = [[view1 alloc]init];
[abc someMethod];
[abc release];
}
我希望你得到它了。
答
如果您有类(.m文件)内2个功能:
- (无效)FUNC1 {}
- (无效)FUNC2 {}
如果你想从func1调用func2,你不能只调用func2();
,而不是仅仅包括self
即:
-(void) func1{
[self:func2];
}
这不是很清楚。请尝试更长的描述。也许你在谈论@selector? – Nimrod 2010-10-12 04:02:56
假设在didFinishinLaunchingmethod我必须调用 - (IBAction)检查;方法...我怎么称呼它? – 2010-10-12 04:08:19
请考虑为您的问题使用更具描述性的标题。这一个是非常一般的。 – 2010-10-12 05:17:19