现在的位置: 首页 > 软件开发 > 正文

Tableview图片后载入lazy tableview load

2010年11月25日 软件开发 ⁄ 共 899字 暂无评论 ⁄ 被围观 12+

Tableview图片后载入参见示例: http://developer.apple.com/iphone/library/samplecode/LazyTableImages/Listings/Classes_RootViewController_m.html

NSThread 实现代码:

[php]- (id)initWithTarget:(id)trgt selector:(SEL)sel withImgURL:(NSString *)url {
if(self = [super init]) {
if(url == nil ||

)
return nil;
target = trgt;
action = sel;
imgURL = [[NSURL alloc] initWithString: url];
}
return self;
}

- (void)main {
[NSThread detachNewThreadSelector:@selector(loadImage) toTarget:self withObject:nil];
}

- (void)loadImage {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
UIImage *img = [UIImage imageNamed: @"default_user.png"];
if(![[imgURL absoluteString] isEqualToString: @"0"]) {
NSData *imgData = [NSData dataWithContentsOfURL: imgURL];
img = [UIImage imageWithData: imgData];
}
if([target respondsToSelector: action])
[target performSelectorOnMainThread: action withObject: img waitUntilDone: YES];
[pool release];
}

- (void)dealloc {
[imgURL release];
[super dealloc];
} [/php]

给我留言

您必须 [ 登录 ] 才能发表留言!

×
#