在tableView中加载缩略图图像

时间:2015-04-15 03:14:11

标签: ios objective-c uitableview parse-platform thumbnails

我在UITableView中有一个UIViewController,我正在尝试将imageFile作为缩略图加载到UITableViewCell中。所有UITableViewCell数据都是从解析中加载的,我可以成功将NSObject名称和用户名加载到UITableViewCell中,但由于某些原因,我的拇指图像会出错。我的代码如下(对于单元格)。

#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 self.groups.count;
}


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


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

// Configure the cell...

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
PFObject *group = [self.groups objectAtIndex:indexPath.row];

PFFile *thumbnail = [group objectForKey:@"imageFile"];
PFImageView *thumbnailImageView = (PFImageView*)[cell viewWithTag:100];
thumbnailImageView.layer.cornerRadius = thumbnailImageView.frame.size.width/2;
thumbnailImageView.layer.masksToBounds = YES;
thumbnailImageView.image = [UIImage imageNamed:@"cc"];
thumbnailImageView.file = thumbnail;
[thumbnailImageView loadInBackground];

UILabel *nameLabel = (UILabel*) [cell viewWithTag:101];
nameLabel.text = [group objectForKey:@"name"];
UILabel *usernameLabel = (UILabel*) [cell viewWithTag:103];
usernameLabel.text = [group objectForKey:@"creatorName"];


return cell;
}

2 个答案:

答案 0 :(得分:0)

似乎[cell viewWithTag:100]是故事板中的UIImageView。尝试在身份检查器中将UIImageView类设置为PFImageView,希望这也能解决您的问题。

祝你好运

答案 1 :(得分:0)

您正在将对象分配给PFFile:

PFFile的正确用法是:

PFFile *thumbnail = [PFFile fileWithName:fileName data:fileData];

PFObject的正确用法是:

 PFObject *group = [PFObject objectWithClassName:@"your class name"];