我的应用程序有一个带有自定义单元格的TableView。
我想指定使用Parse.com
我希望我的单元格有一个根据称为...的数据类型的图像,例如:
如果查询包含等待完成的数据,则单元格必须具有图片“红色图像”
除此以外
如果查询包含已完成的数据,则该单元格必须具有“绿色图像”。
我该怎么办?如果解释困难,我深表歉意,但是我想要的结果是,应用程序的用户可以通过表视图的显示来确定要完成哪些数据,哪些不完成。
最佳答案
在您的Parse.com类中-添加带有dataCompleted
值的列bool
。
在cellForRowAtIndexPath
(对于UITableView
)或cellForItemAtIndexPath
(对于UICollectionView
)内处理查询结果时,请检查dataCompleted
键的布尔值并相应地设置图像。
// _dataSource is an array of PFObjects from the Parse.com query
PFObject *rowObject = [_dataSource objectAtIndex:indexPath.row];
if([[rowObject objectForKey:@"dataCompleted"] boolValue])
{
// Data is completed
cell.outletDataCompletedImageView.image = [UIImage imageNamed:@"icon_dataiscompleted"];
}
else
{
// Data still to be completed
cell.outletDataCompletedImageView.image = [UIImage imageNamed:@"icon_datastilltobecompleted"];
}
关于ios - 根据检索到的数据类型创建自定义单元格,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19185160/