Iphone 如何从目标c中的第二类访问第一类方法
我已经编写了两个类,其中包含相同的方法(print)。我想使用第二类对象访问第一类打印方法。我怎样才能做到这一点 代码: 现在我创建了第二类对象,如Iphone 如何从目标c中的第二类访问第一类方法,iphone,objective-c,inheritance,polymorphism,Iphone,Objective C,Inheritance,Polymorphism,我已经编写了两个类,其中包含相同的方法(print)。我想使用第二类对象访问第一类打印方法。我怎样才能做到这一点 代码: 现在我创建了第二类对象,如 classB *B = [classB alloc]init]; 使用委托访问其他类 你也可以这样做 @implementation view1 (void)someMethod { ......code of method... } @implementation view2 (void)fistMethod { view1 *
classB *B = [classB alloc]init];
使用委托访问其他类
你也可以这样做
@implementation view1
(void)someMethod
{
......code of method...
}
@implementation view2
(void)fistMethod
{
view1 *abc = [[view1 alloc]init];
[abc someMethod];
[abc release];
}
还要检查一下这一点我们如何使用@protocol实现这一点?我是一个新的目标c。。。请在这方面提出建议。谷歌“objective c delegate pattern”有成千上万的结果和很好的例子。这里是第一个:我从这个堆栈溢出链接得到的答案可能是重复的。谢谢。另外,您还应该大写您的类名,即ClassBTry委托功能来调用该方法
@implementation view1
(void)someMethod
{
......code of method...
}
@implementation view2
(void)fistMethod
{
view1 *abc = [[view1 alloc]init];
[abc someMethod];
[abc release];
}