在目标C上从静态方法调用非静态方法 [英] Calling non static method from static method on Objective C

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

问题描述

如何从同一对象的静态方法中调用非静态方法?

How can I call a non-static method from a static method in same object?

在静态方法中:如果我使用 [ClassName nonStaticMethod] 或者如果我使用 [self nonStaticMethod] 我得到警告:找不到类方法"+ isTrancparentImageWithUrl:"(返回类型默认为"id")

Inside the static method: if I use [ClassName nonStaticMethod] Or If I use [self nonStaticMethod] I get warning: Class method '+isTrancparentImageWithUrl:' not found (return type defaults to 'id')

推荐答案

您需要创建类的对象才能调用非类方法,您需要一个实例来调用此类方法,这就是为什么将这些方法称为实例方法的原因.

You need to create the object of the class to call non class methods, You need an instance to call such methods that is why those methods are called instance methods.

调用 [self instanceMethod] 是行不通的,因为类方法中的 self 指向该类而不是任何实例.此处您可以在类方法中找到有关使用 self 的信息.

calling [self instanceMethod] from class method wont work, because self in class method points to the class rather any instance. Here you can find information the on use of self in class methods.

这篇关于在目标C上从静态方法调用非静态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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