2014-02-21 44 views
2

目前,我使用下面的代碼:PFQueryTableViewController不加載圖像parse.com

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object { 

static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier  forIndexPath:indexPath]; 

if (!cell) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 



PFFile *file = [object valueForKeyPath:@"exercicio.foto"]; 
[file getDataInBackgroundWithBlock:^(NSData *data, NSError *error) { 
    cell.imageView.image = [[UIImage alloc] initWithData:data]; 
    [cell setNeedsLayout]; 
}]; 

return cell; 
} 

這工作,但圖像的時間太長加載,滾動時的視覺效果不那麼好。我嘗試使用PFTableViewCell,但是當我嘗試從我的PFFile解析出來的消息中,發現無法識別的選擇器發送到cell.imageView.file中的實例。現在,當我將故事板中的類更改爲PFTableViewCell時,應用程序不會崩潰,但也不會加載圖像。

這是讓我崩潰的代碼,或者如果我將故事板更改爲PFTableViewCell,它不會顯示圖像。

- (PFTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object { 

static NSString *CellIdentifier = @"Cell"; 
PFTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

if (!cell) { 
    cell = [[PFTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:CellIdentifier]; 
} 
cell.imageView.file = [object valueForKeyPath:@"exercicio.foto"]; 

return cell; 
} 

我真的需要幫助,我已經嘗試了很多東西,但似乎沒有任何工作。謝謝。

回答

0

如果問題是您的圖片加載時間過長,我建議您創建圖片的縮略圖版本,然後在tableview中使用這些圖片。然後,如果您從tableview轉到detail-view,則加載完整大小的圖像。

0

你必須設置你的PFImageView

- (void)loadInBackground 

解析文檔描述的文件值之後調用loadInBackground的文件屬性證實:

解析的服務器上存儲圖像的遠程文件。請注意, 下載在調用loadInBackground:之前不會啓動。

還有一個完成塊的方法:

- (void)loadInBackground:(void (^) (UIImage *image , NSError *error))completion 
+0

我試着這一點,仍然沒有工作 – Camus

1

這工作

PFFile *thumbnail = object[@"imageFile"]; 

    cell.imageView.image = [UIImage imageNamed:@"857-rocket.png"]; 
    cell.imageView.file = thumbnail; 

    [cell.imageView loadInBackground];