如何在iOS应用中进行自定义委托 [英] How to make Custom Delegate in iOS app

查看:62
本文介绍了如何在iOS应用中进行自定义委托的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPhone中,每个UIContrrol都有预定义的委托方法,但是我们将如何创建自己的自定义委托方法

In iPhone every UIContrrol has predefined delegate methods but how we will create our own custom delegate methods

推荐答案

在您的类中创建一个id对象委托.创建一个getter和setter,以便其他类可以将自己设置为委托. 在您的班级中添加以下内容:

In your class create an id object delegate. Create a getter and setter so other classes can set themselves as delegates. In your class add this:

@interface MyClass (Private)
-(void)myDelegateMethod;
@end

然后在要调用的类的任何函数中执行以下操作:

Then in what ever function you want to call back to the class that is the delegate do something like this:

if ( [delegate respondsToSelector:@selector(myDelegateMethod)] ) {
[delegate myDelegateMethod];
}

这篇关于如何在iOS应用中进行自定义委托的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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