自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iPhone學(xué)習(xí)之路 Table實(shí)現(xiàn)動(dòng)態(tài)加載圖片

移動(dòng)開發(fā) iOS
本文介紹的是iPhone學(xué)習(xí)之路 Table實(shí)現(xiàn)動(dòng)態(tài)加載圖片,主要講述的是對圖片的操作,我們來看內(nèi)容。

iPhone學(xué)習(xí)之路 Table實(shí)現(xiàn)動(dòng)態(tài)加載圖片是本文要介紹的內(nèi)容,內(nèi)容不多,基于代碼實(shí)現(xiàn),我們一起來看內(nèi)容。

Iphone在加載列表時(shí),如果每個(gè)等待把所有列表中的數(shù)據(jù)都加載完在顯示相關(guān)內(nèi)容,如果列表中有一些比較大的圖片,加載的時(shí)間比較長,那么給用戶的效果就很差了,下面詳細(xì)是一種實(shí)現(xiàn)動(dòng)態(tài)加載圖片的辦法:

  1. - (UITableViewCell *)tableView:(UITableView *)tableView   
  2.          cellForRowAtIndexPath:(NSIndexPath *)indexPath {   
  3.     UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"tag"];   
  4.     if (cell==nil) {   
  5.         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle   
  6.                                        reuseIdentifier:@"tag"] autorelease];   
  7.     }      
  8.     //表格設(shè)計(jì)   
  9.     NSDictionary* one = [array objectAtIndex:indexPath.row];   
  10.     cell.textLabel.text = [one objectForKey:@"title"];   
  11.     cell.detailTextLabel.text = [one objectForKey:@"content"];   
  12.      [NSThread detachNewThreadSelector:@selector(updateImageForCellAtIndexPath:) toTarget:self withObject:indexPath];   
  13.     return cell;   
  14. }   
  15.  
  16. - (void)updateImageForCellAtIndexPath:(NSIndexPath *)indexPath   
  17. {   
  18.     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];   
  19.     UIImage *image = [self getImageForCellAtIndexPath:indexPath];   
  20.     UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];   
  21.     [cell.imageView performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:NO];   
  22.     [image release];   
  23.     [pool release];   
  24. }   
  25. -(UIImage *)getImageForCellAtIndexPath:(NSIndexPath *)indexPath   
  26. {   
  27.     id path = [[array objectAtIndex:indexPath.row] objectForKey:@"image"];   
  28.     NSURL *url = [NSURL URLWithString:path];   
  29.     NSData *data = [NSData dataWithContentsOfURL:url];   
  30.     UIImage *image = [[UIImage alloc] initWithData:data cache:NO];   
  31.     return image;   

源代碼:http://easymorse-iphone.googlecode.com/svn/trunk/WelcomePavilion/

小結(jié):iPhone學(xué)習(xí)之路 Table實(shí)現(xiàn)動(dòng)態(tài)加載圖片的內(nèi)容介紹完了,希望本文對你有所幫助!

本文來自:http://wangjun.easymorse.com/?p=908

責(zé)任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-07-25 15:32:06

iPhone Table 動(dòng)態(tài)

2011-07-06 16:15:46

iPhone 圖片

2011-07-26 09:32:08

iPhone 模擬器

2023-10-10 15:32:09

veImageXWeb 圖片

2011-07-25 16:47:01

HTTP Server PUSH

2023-04-25 17:24:31

veImageXiOSSDK

2011-07-08 15:08:16

iPhone 圖片

2011-07-22 13:30:52

JavaScript

2011-08-10 16:44:56

iPhone代理設(shè)計(jì)模式

2009-08-28 16:14:26

C#實(shí)現(xiàn)加載動(dòng)態(tài)庫

2013-06-27 11:16:27

Android異步加載

2011-07-21 17:29:42

iPhone Sqlite 數(shù)據(jù)庫

2011-07-27 17:07:06

iPhone 游戲 Cocos2d

2011-08-19 11:10:31

iPhone應(yīng)用

2021-10-18 12:04:22

Spring BootJava開發(fā)

2021-10-18 10:36:31

Spring Boot插件Jar

2022-09-23 15:01:33

圖片加載代碼

2014-07-28 14:04:26

2011-08-16 18:13:42

IPhone開發(fā)UIView動(dòng)畫

2010-01-27 14:39:58

Android圖片大小
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號