且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在iOS应用中进行自定义委托

更新时间:2022-12-11 15:32:42

在您的类中创建一个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];
}