0
我有一个UDPSocket在我的控制器之一,我知道我必须使用代表。我必须添加哪些功能才能使其从另一个控制器访问我的udpsocket?如何使用委托从另一个控制器发送消息到另一个控制器?
这将是伟大的使用不便像
[controller1.udpsocket sendData:data toHost:host]
,但我知道它不好,做什么,而不是它?
我有一个UDPSocket在我的控制器之一,我知道我必须使用代表。我必须添加哪些功能才能使其从另一个控制器访问我的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];
}
以及如何调用此函数? – 2012-04-05 14:34:15
我想我明白了,我需要将这些方法设置为公开吗? – 2012-04-10 11:44:52
在DowmLoadImage类中,一旦完成下载,就调用委托方法,如下所示: - (void)connectionDidFinishLoading:(NSURLConnection *)连接UIImage * image = [[UIImage alloc] initWithData:mData]; \t if(mDelegate && [mDelegate respondsToSelector:@selector(ImageDownLoaded:)]){ \t \t [mDelegate ImageDownLoaded:image]; \t} \t [mConnection release]; \t [image release]; \t [mData release]; } – sample 2012-04-11 06:26:01