PFImageView url displaying parse

烈酒焚心 提交于 2019-12-02 19:53:05

问题


It has been 1 week and I am still stuck on PFImageView. I remade everything. Changed from UITableView to PFQueryTableView, then tried to display image with UITableViewCell, then with PFTableViewCell and in every method only things that works to display are labels. Everytime when I run my app I get crash(SIGABRT) because of this line: `

Crashing line

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

Can anyone help me to solve this problem? Thanks a lot

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

回答1:


PFImageView links only to files stored on Parse.com and represented by PFFile objects. You can't set cell.imagevieww.file to a string and have it work.

If you are using normal URLs to arbitrary images on the web then you should use SDWebImage (or a similar generic solution) for the image view on your cell.


With SDWebImage you would replace:

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

with:

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


来源:https://stackoverflow.com/questions/21149468/pfimageview-url-displaying-parse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!