获取调用方法的对象 [英] Get the object which called a method

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

问题描述

如果我在这样的随机课程中打过电话:

If I have a call from within a random class like this:

@implementation SomeClass

- (void) classMethodFoo
{
    int a = [SomeSingleton sharedInstance].aValue;
}

@end

SomeSingleton sharedInstance内部,是否有一种方法可以获取对调用此方法的对象的引用(当然,不将调用的传递自身作为参数)?

Inside SomeSingleton sharedInstance, is there a way to get a reference to the object which called this method (without the called passing self as a parameter of course)?

推荐答案

否,有关呼叫者的信息不会自动传递.

No, information about the caller isn't passed along automatically.

这就是为什么例如IBAction方法具有sender参数的原因,以及为什么委托方法经常具有引用委托对象的参数的原因.

This is why IBAction methods, for instance, have a sender parameter, and why delegate methods often have a parameter that refers to the delegate's object.

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

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