【问题标题】:Parse.com adding images via URLParse.com 通过 URL 添加图像
【发布时间】:2014-01-24 12:34:09
【问题描述】:

我只是想问一下如何通过 URl 向我的 Parse TableView 添加一些图像。我坚持下去。我用自定义单元格制作了它。标签效果很好。你能帮我添加图像视图吗? 谢谢米兰

 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

#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

【问题讨论】:

标签: ios image url parse-platform


【解决方案1】:

使用PFImageView 解析以显示图像文件(PFile)。将您的 UIImageView 更改为 PFImageVIew
如果您有 xib 文件,请更改您的课程。

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

cellForRow

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

【讨论】:

  • 感谢您的快速回答。我ve got one more problem. After I changed UIimageView to PFImageView I cant 将 segue 与 imageview(通过 ctrl)连接,如果运行应用程序我会出错。你能帮我吗?非常感谢
  • 我更新了我的答案,将类更改为 PF,并与 IBOutlet 连接
  • 还是不要t got it. Dont知道原因。我认为一切都很好。我已经连接了。 postimg.org/image/jys3hqegt
  • Its probably because of this line [cell.imageview loadInBackground];. Dont 知道任何其他选项如何修复。
  • 上图不清楚你的问题是什么,你可以创建一个方法来设置单元格并传递一个PFObject,然后编写代码来显示数据。
【解决方案2】:

如果有人有同样的问题。我已经用 With SDWebImage 修复了它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-14
    • 2020-12-16
    • 1970-01-01
    • 1970-01-01
    • 2016-03-18
    相关资源
    最近更新 更多