// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier] autorelease];
}
[NSThread detachNewThreadSelector:@selector(updateImageForCellAtIndexPath:) toTarget:selfwithObject:indexPath];
UIFont *font = [UIFont fontWithName:@"Helvetica" size:17];
//cell.textLabel.text = [dataArray objectAtIndex:indexPath.row];
cell.textLabel.text = @"ok";
cell.textLabel.font = font;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (void)updateImageForCellAtIndexPath:(NSIndexPath *)indexPath{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
UIImage *image = [self getImageForCellAtIndexPath:indexPath];
if (image) {
NSLog(@"image ok %d",indexPath.row);
}
UITableViewCell *cell = [self.tbView cellForRowAtIndexPath:indexPath];
CGRect rect;
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(KNewCollectionImageViewX+5, kTopButtonMargin,KShopCellImageViewWidth, KShopCellImageViewHeight)];
iv.tag = KImageViewTag;
iv.backgroundColor = [UIColor clearColor];
rect = iv.frame;
//iv.image = image;
[cell addSubview:iv];
//cell.imageView.image = image;
//[cell.imageView performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:NO];
[iv performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:NO];
[iv release];
//[image release];
[pool release];
}
-(UIImage *)getImageForCellAtIndexPath:(NSIndexPath *)indexPath{
// id path = [[dataArray objectAtIndex:indexPath.row] objectForKey:@"image"];
//id path = [imageArray objectAtIndex:indexPath.row];
//id path = @"http://merrimusings.mu.nu/archives/images/groundhog2.jpg";
NSString *path = @"http://merrimusings.mu.nu/archives/images/groundhog2.jpg";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
//UIImage *image = [[UIImage alloc] initWithData:data cache:NO];
// NSURL *url = [NSURL URLWithString:path];
//NSData *data = [NSData dataWithContentsOfURL:url];
//UIImage *image = [[UIImage alloc] initWithData:data cache:NO];
//UIImage *image = [[UIImage alloc] initWithData:data cache:NO];
UIImage *image = [UIImage imageWithData:data];
if (image) {
NSLog(@"%@",path);
}
return image;
}