2014-01-06 32 views
0

我只是想問如何通過URl添加到我的Parse TableView一些圖像。我堅持了。我用自定義單元格做了它。標籤的作品很好。你可以幫我添加imageview嗎? 感謝米蘭Parse.com通過URL添加圖像

TableViewController.h 

> #import <UIKit/UIKit.h> 
> #import "Parse/Parse.h" 
> #import "CustomCell.h" 
> 
> @interface TableViewController : UITableViewController 
> <UITableViewDelegate,UISearchDisplayDelegate, UISearchBarDelegate> { 
>  
>  NSArray *colorsArray; 
>  NSArray *searchResults; 
>  } 
> 
> @property (strong, nonatomic) IBOutlet UITableView *colorsTable; 
> 
> 
> 
> @end 

TableViewController.m

@interface TableViewController() 

@end 
@implementation TableViewController 


@synthesize colorsTable; 

- (void) retrieveFromParse { 

    PFQuery *retrieveColors = [PFQuery queryWithClassName:@"Hracky1"]; 
    [retrieveColors findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 
     if (!error) { 
      colorsArray = [[NSArray alloc] initWithArray:objects]; 
     } 
     [colorsTable reloadData]; 
    }]; 
    [self.colorsTable reloadData]; 
    [self.refreshControl endRefreshing]; 
} 

- (id)initWithStyle:(UITableViewStyle)style 
{ 
    self = [super initWithStyle:style]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 


- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    [self performSelector:@selector(retrieveFromParse)]; 

    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; 

    self.refreshControl = refreshControl; 

    [refreshControl addTarget:self action:@selector(retrieveFromParse) 
    forControlEvents:UIControlEventValueChanged]; 
} 

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

#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    return colorsArray.count; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"colorsCell"; 

    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    PFObject *tempObject = [colorsArray objectAtIndex:indexPath.row]; 

    [cell.imageview setFile: [tempObject objectForKey:@"ImageURL"]]; 
    [cell.imageview loadInBackground]; 

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

    return cell; 
} 



@end 

CustomCell.h

#import <UIKit/UIKit.h> 
#import "Parse/Parse.h" 

@interface CustomCell : UITableViewCell 
@property (strong, nonatomic) IBOutlet UILabel *cellTitle; 
@property (strong, nonatomic) IBOutlet UILabel *cellDescript; 
@property (strong, nonatomic) IBOutlet PFImageView *imageview; 


@end 

CustomCell.m

使用 PFImageView用於顯示的圖像文件(PFILE)
#import "CustomCell.h" 

@implementation CustomCell 
@synthesize cellTitle; 
@synthesize cellDescript; 
@synthesize imageview; 

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{ 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     // Initialization code 
    } 
    return self; 
} 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated 
{ 
    [super setSelected:selected animated:animated]; 

    // Configure the view for the selected state 
} 

@end 
+0

已經解決了這個問題。 [點擊這裏] [1] [1]:http://stackoverflow.com/questions/21149468/pfimageview-url-displaying-parse – Milan1111

+0

我已經解決了這個問題。 [點擊這裏] [1] [1]:http://stackoverflow.com/questions/21149468/pfimageview-url-displaying-parse – Milan1111

回答

0

解析。改變你的UIImageViewPFImageVIew
如果你有xib文件,改變你的班級。
enter image description here

@property (strong, nonatomic) IBOutlet PFImageView *imageview; 

cellForRow

 [cell.imageview setFile: [tempObject objectForKey:@"ImageURL"]];     
    [cell.imageview loadInBackground]; 
+0

感謝您快速的回答。我還有一個問題。在將UIimageView更改爲PFImageView後,我無法將segue與imageview連接(通過ctrl),如果運行該應用程序,則會出現錯誤。你能幫我嗎?非常感謝 – Milan1111

+0

我更新了我的答案,將課程更改爲PF,並連接IBOutlet – HoanNguyen

+0

仍然沒有收到答案。不知道原因。我認爲一切都很好。我已經連接了它。 http://postimg.org/image/jys3hqegt/ – Milan1111

0

如果有人有同樣的問題。我已經用SDWebImage修復了它。