2014-10-28 45 views
0

一切工作正常,除了在一個令人不安的延遲後,單元格中的圖像顯示出來。在tableView完成加載後大約0.3秒。我認爲很短的時間內顯示一個空白圖像是非常醜陋的...在UITableVIew加載之前從解析中檢索圖像?

如何才能讓tableView在剛剛加載parse的圖像後顯示(爲什麼不從緩存中首先?)。或者我可以讓啓動屏幕保持更長時間..? TableView是應用程序中的初始視圖。

queryForTable

- (PFQuery *)queryForTable { 
    PFQuery *query = [PFQuery queryWithClassName:self.parseClassName]; 

    // If no objects are loaded in memory, we look to the cache 
    // first to fill the table and then subsequently do a query 
    // against the network. 
    if ([self.objects count] == 0) { 
     query.cachePolicy = kPFCachePolicyCacheThenNetwork; 

    } 

    [query orderByAscending:@"name"]; 

    return query; 
} 

的cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)objects 
{ 
    static NSString *simpleTableIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; 
    } 

    //loading icons 
    PFFile *thumbnail = [objects objectForKey:self.imageKey]; 
    PFImageView *thumbnailImageView = (PFImageView*)[cell viewWithTag:100]; 
    thumbnailImageView.file = thumbnail; 
    thumbnailImageView.image = [UIImage imageNamed:@"placeholder.jpg"]; 


    [thumbnailImageView loadInBackground:^(UIImage *image, NSError *error) { 
     if (!error) { 

     } 
    }]; 



    //cell 
    cell.textLabel.text = [objects objectForKey:self.textKey]; 

    return cell; 
} 

感謝提前:)

回答

1

有一個短暫的延遲後加載圖像沒有壞處。這是一個標準程序,隨後是許多世界級應用程序(曾嘗試在Facebook或Twitter應用程序中滾動)。從邏輯和程序的角度來看,解決這個問題的工作會非常麻煩。

+0

也許這是真的,但有可能使單元格從緩存中顯示圖像的第0,3秒?或者至少創建一個像其他應用程序的加載屏幕? – Tibbe 2014-10-28 14:20:26

+0

是的,它肯定是可能的。你會想知道更多關於UIActivityIndi​​catorView及其用法。 – 2014-10-28 14:21:56

+0

好吧,但更快地設置緩存是不可能的吧?顯示啓動屏幕直到對象完成加載爲止呢? – Tibbe 2014-10-28 14:24:28

1

我認爲做這件事的最好方法就是facebook在他們的應用程序上執行此操作的方式。 Facebook在圖像所屬的位置顯示一個空的灰色容器,一旦圖像被下載,它們就會以動畫的方式淡入。我認爲這是一條路要走的原因是因爲在準備好加載圖像並準備好加載另一個圖像似乎沒有意義,最好是隻需容納一個空容器並準備好加載圖像。