#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];
}
この関数をどのように呼び出すことができますか? –
私は理解したと思う、私はこのメソッドを公開する必要がありますか? –
DowmLoadImageクラスでデリゲートメソッドを呼び出すと、ダウンロードが終了します。 - (void)connectionDidFinishLoading:(NSURLConnection *)connection { \t UIImage * image = [[UIImage alloc] initWithData:mData]; \t IF(mDelegate && [mDelegate respondsToSelector:@selector(ImageDownLoaded:)]){ \t \t \t [mDelegate ImageDownLoaded:画像]。 \t} \t [mConnection release]; \t [image release]; \t [mData release]; } – sample