我的一个 Controller 中有一个 UDPSocket,我知道我必须使用委托(delegate)。我必须添加哪些功能才能使其从另一个 Controller 访问我的 udpsocket?
使用像这样的东西会很棒
[controller1.udpsocket sendData:data toHost:host]
但我知道它不好,该怎么办呢?
最佳答案
#import <Foundation/Foundation.h>
@protocol DownLoadImageDelegate<NSObject>
@required
-(void)ImageDownLoaded:(UIImage*)image;
@end
@interface DownLoadImage : NSObject
{
id<DownLoadImageDelegate> mDelegate;
NSURLConnection *mConnection;
NSMutableData *mData;
}
@property(nonatomic,retain) id<DownLoadImageDelegate> delegate;
@end
//InViewController class
DownLoadImage *imageDownLoad = [[DownLoadImage alloc]init];
imageDownLoad.delegate=self;
//and implement the delegate method declared in DownLoadImage class in ViewController class as
-(void)ImageDownLoaded:(UIImage *)image
{
NSLog(@"Image%@",image);
[mImageView setImage:image];
}
关于ios - 如何使用委托(delegate)从一个 Controller 向另一个 Controller 发送消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9872859/