iOS 네트워크 NSURL 2
#import <UIKit/UIKit.h>
@interface MyImageView : UIImageView<NSURLConnectionDataDelegate>
@property (retain, nonatomic) NSMutableData *data;
-(void)setMyImageViewUrl:(NSURL *)url;
@end
#import "MyImageView.h"
@implementation MyImageView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
-(void)setMyImageViewUrl:(NSURL *)url
{
self.data=[NSMutableData data];
NSMutableURLRequest *request=[[NSMutableURLRequest alloc]init];
[request setHTTPMethod:@"GET"];
[request setURL:url];
[request setTimeoutInterval:60];
[NSURLConnection connectionWithRequest:request delegate:self];
}
#pragma mark---NSUrlConnectionData delegate
//
//
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[self.data appendData:data];
}
//
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
UIImage *image=[UIImage imageWithData:self.data];
self.image=image;
}
@end
#import "MyAppDelegate.h"
#import "UIImageView+catchImage.h"
#import "MyImageView.h"
@implementation MyAppDelegate
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
// UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(60, 20, 200, 120)];
// [imageView setImageUrl:[NSURL URLWithString:@"http://news.imust.cn/UploadFiles/2013/2/2013112015485327367.jpg"]];
// [self.window addSubview:imageView];
MyImageView *imageView=[[MyImageView alloc]initWithFrame:CGRectMake(60, 20, 200, 120)];
[imageView setMyImageViewUrl:[NSURL URLWithString:@"http://b.hiphotos.baidu.com/baike/c0%3Dbaike80%2C5%2C5%2C80%2C26/sign=26a4246642a7d933aba5ec21cc22ba76/5ab5c9ea15ce36d3fc2e9d423af33a87e850352ac65c99a5.jpg"]];
[self.window addSubview:imageView];
return YES;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.