2009-12-13 22 views

回答

3

我沒有這個做我自己,但我的想法是創建一個處理呈現,而圖像加載UIActivity指示我自己的UIView子類。然後將該視圖的實例添加到您的表格單元格中,而不是普通的UIImageViews。

更新: OK,就像我之前說的,我沒有這樣做我自己。下面只是輸入到瀏覽器中,我不知道你是否會遇到與線程的任何問題,但它應該給你一個想法,如何處理這個:

@interface IndicatorImageView : UIView { 
    UIImageView *imageView; 
    UIActivityIndicatorView *indicator; 
    NSString *imageName; 
    NSURL *imageURL; 
} 
@property (nonatomic, copy) NSString *imageName; 
@property (nonatomic, retain) NSURL* imageURL; 
@end 

@implementation IndicatorImageView 
@synthesize imageName; 
@synthesize imageURL; 
- (id)initWithFrame:(CGRect)frame { 
    if (self = [super initWithFrame:frame]) { 
     imageView = [[UIImageView alloc] initWithFrame:self.bounds]; 
     [self addSubview:imageView]; 

     indicator = [[UIActivityIndicatorView alloc] initWithFrame:self.bounds]; 
     [self addSubview:indicator]; 
    } 
    return self; 
} 
- (void)setImageName:(NSString *)anImageName { 
    if (imageName == anImageName) { 
     return; 
    } 
    [imageName release]; 
    imageName = [anImageName copy]; 

    // optionally remove the old image while we're updating 
    //imageView.image = nil; 

    [indicator startAnimating]; 
    [self performSelectorInBackground:@selector(updateImageViewUsingImageName) withObject:nil]; 
} 
- (void)setImageURL:(NSURL *)anImageURL { 
    if (imageURL == anImageURL) { 
     return; 
    } 
    [imageURL release]; 
    imageURL = [anImageURL copy]; 

    // optionally remove the old image while we're updating 
    //imageView.image = nil; 

    [indicator startAnimating]; 
    [self performSelectorInBackground:@selector(updateImageViewUsingImageURL) withObject:nil]; 
} 
- (void)updateImageViewUsingImageName { 
    NSAutoreleasepool *pool = [[NSAutoreleasePool alloc] init]; 
    imageView.image = [UIImage imageNamed:imageName]; 
    [indicator performSelectorOnMainThread:@selector(stopAnimating) withObject:nil]; 
    [pool release]; 
} 
- (void)updateImageViewUsingImageURL { 
    NSAutoreleasepool *pool = [[NSAutoreleasePool alloc] init]; 
    NSData *imageData = [NSData dataWithContentsOfURL:imageURL]; 
    imageView.image = [UIImage imageWithData:imageData]; 
    [indicator performSelectorOnMainThread:@selector(stopAnimating) withObject:nil]; 
    [pool release]; 
} 
@end 

當您設置imageName屬性,圖像將在後臺加載,而UIActivityIndicatorView正在進行動畫處理。一旦圖像加載並設置在UIImageView上,我們停止動畫活動指示器。

+0

我已經添加了一些代碼。 HTH – 2009-12-14 02:26:24

+0

謝謝你your'e冠軍隊友 – Doz 2009-12-14 03:41:51

+0

不知道如何將cell.imageView。(image?)分配給這個子類Tim – Doz 2009-12-15 00:50:00

1

如果我能記得正確的話,那麼在從斯坦福講座cs193,iPhone應用程序編程,以及從Twitter帳戶加載個人資料照片時就會顯示出來。

尋找合適的演示文稿(我不記得它是哪一個),看看有關桌面視圖的筆記,然後看看演講的itunesu視頻。

http://www.stanford.edu/class/cs193p/cgi-bin/index.php

1

子類UIImage並添加UIActivityIndi​​cator作爲子視圖。爲類設置圖像源添加一些方法,並適當地啓動/停止UIActivityIndi​​cator。