简体   繁体   English

Parse.com通过URL添加图像

[英]Parse.com adding images via URL

I just wanted to ask how to add to my Parse TableView via URl some images. 我只是想问一下如何通过URl向我的Parse TableView添加一些图像。 I`m stuck with it. 我坚持下去。 I made it with custom cells. 我用自定义单元格制作而成。 Labels works good.Can you help me please with adding imageview? 标签效果很好。能帮我添加imageview吗? Thanks Milan 谢谢米兰

 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 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 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 CustomCell.m

 #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 

Parse using PFImageView for display a image file(PFile). 使用PFImageView进行解析以显示图像文件(PFile)。 Change your UIImageView to PFImageVIew 将您的UIImageView更改为PFImageVIew
if you have xib file, change your class. 如果您有xib文件,请更改您的课程。
在此处输入图片说明

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

In cellForRow : cellForRow

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

If someone have a same problem. 如果有人有同样的问题。 I already fixed it with With SDWebImage. 我已经使用SDWebImage修复了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM