【问题标题】:Query images to UITableView查询图片到 UITableView
【发布时间】:2014-09-25 04:51:41
【问题描述】:

我正在尝试查询 UITableview 中的图像,但在尝试配置单元格时遇到问题。

【问题讨论】:

  • 你需要在主线程上重新加载表格,而不是后台线程。

标签: ios objective-c uitableview


【解决方案1】:

创建UITableViewCell 的子类并向其添加UIImageView 属性。以下是您的头文件的示例:

#import <UIKit/UIKit.h>

@interface CustomTableViewCell : UITableViewCell

@property (nonatomic, weak) IBOutlet UIImageView *icon;

//@property (nonatomic, strong) UIImageView *icon; //Only if you're not using an XIB/storyboard

@end

然后,您的 cellForRowAtIndexPath: 函数将类似于以下内容:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier=@"cellimage";
    CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    //the following assumes that your self.images array contains UIImages
    cell.icon.image = [self.images objectAtIndex:indexPath.row];

    return cell;
}

另外,请务必在主线程上调用reloadData

【讨论】:

  • 但是我应该在 UIImage *yourImage 中放什么
  • 无论您的图像是什么。您如何从PFObjects 中获取图片?
  • 我在问你这个问题,我不知道你在PFObjects 中存储了什么。
  • 好吧,看看我的编辑。你需要弄清楚你的图像是如何存储的,然后将它们相应地放入图像视图中。
  • 这可能对你有帮助:stackoverflow.com/questions/24052510/…
猜你喜欢
  • 1970-01-01
  • 2011-08-15
  • 2014-12-14
  • 2022-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多