2014-01-15 111 views
0

已經1周了,我仍然堅持PFImageView。我重拍了一切。從UITableView更改爲PFQueryTableView,然後嘗試使用UITableViewCell顯示圖像,然後使用PFTableViewCell顯示圖像,並且在每種方法中只顯示標籤。每次當我運行我的應用程序,我得到崩潰(SIGABRT),因爲這行:`PFImageView url顯示解析

轟然線

cell.imagevieww.file= [object objectForKey:@"ImageURL"]; 
     [cell.imagevieww loadInBackground]; 

誰能幫我解決這個問題呢?非常感謝

TableViewController.h

#import <Parse/Parse.h> 
#import "Customcell.h" 
#import "DetailViewController.h" 

@interface TableeViewController : PFQueryTableViewController { 

    NSArray *colorsArray; 

} 
@property (strong, nonatomic) IBOutlet UITableView *colorsTable; 




@end 

TableViewController.m

#import "TableeViewController.h" 
    #import "TableViewCell.h" 
    #import "DetailViewController.h" 

    @interface TableeViewController() 

    @end 

    @implementation TableeViewController 
    @synthesize colorsTable; 

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
    { 
     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
     if (self) { 
      // Custom initialization 
     } 
     return self; 
    } 

    - (id)initWithCoder:(NSCoder *)aCoder 
    { 
     self = [super initWithCoder:aCoder]; 
     if (self) { 
      // The className to query on 
      self.parseClassName = @"Hracky1"; 

      // Whether the built-in pull-to-refresh is enabled 
      self.pullToRefreshEnabled = YES; 

      // Whether the built-in pagination is enabled 
      self.paginationEnabled = NO; 
     } 
     return self; 
    } 


    - (void)viewDidLoad 
    { 
     [super viewDidLoad]; 

    } 

    - (void)didReceiveMemoryWarning 
    { 
     [super didReceiveMemoryWarning]; 
     // Dispose of any resources that can be recreated. 

    } 


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

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

     if (cell == nil) { 
      cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 

     } 
     cell.imagevieww.file= [object objectForKey:@"ImageURL"]; 
     [cell.imagevieww loadInBackground]; 

     cell.cellTitle.text = [object objectForKey:@"cellTitle"]; 
     cell.cellDescript.text = [object objectForKey:@"cellDescript"]; 



     return cell; 
    } 

    @end 

Customcell.h

#import <Parse/Parse.h> 

@interface TableViewCell : PFTableViewCell 
@property (strong, nonatomic) IBOutlet UILabel *cellTitle; 
@property (strong, nonatomic) IBOutlet UILabel *cellDescript; 
@property (strong, nonatomic) IBOutlet UILabel *price; 
@property (strong, nonatomic) IBOutlet PFImageView *imagevieww; 
@end 
+0

什麼是'ImageURL',你設置?什麼是崩潰?什麼是異常消息和堆棧跟蹤? – Wain

+0

我在我的parse.com上有名爲ImageURL的String類,我想通過url顯示圖像。我正在製作一些玩具清單,並在標題,說明和價格上標註3個標籤,並在單元格的左側顯示圖像,我將在parse.com上鍵入哪個url地址,刷新後它將與標籤顯示相同。我不想保存圖像。我可以給你發送故事板的照片,如果你想檢查,我的意思是這個。崩潰線向上更新。無論如何,如果我不通過ctrl imagevieww屬性與故事板中的PFImageView連接,它不會崩潰。但什麼也沒有顯示 – Milan1111

回答

5

PFImageView僅鏈接到存儲在Parse.com上的文件並由PFFile對象表示。您不能將cell.imagevieww.file設置爲一個字符串並使其工作。

如果您在網絡上使用任意圖像的普通URL,那麼您應該使用SDWebImage(或類似的通用解決方案)用於單元格上的圖像視圖。


隨着SDWebImage你將取代:

cell.imagevieww.file= [object objectForKey:@"ImageURL"]; 
    [cell.imagevieww loadInBackground]; 

有:

[cell.imagevieww setImageWithURL:[NSURL URLWithString:[object objectForKey:@"ImageURL"]] 
        placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; 
+0

謝謝,我會試試看。 – Milan1111

+0

它可以與Parse.com一起使用嗎?你有沒有嘗試過?謝謝 – Milan1111

+0

做什麼工作? 「PFImageView」與「PFFile」實例一起使用,「SDWebImage」與任意URL一起使用。不清楚你問的是什麼。 – Wain