在swift中打印customTableView单元格中的每5张图像
问题描述:
我有一个大小为50的数组,我想知道是否有方法可以将每个图像从我的数组打印到每个单元格?例如,小区1将有从0图片 - 4,小区2:5 - 9 ...在swift中打印customTableView单元格中的每5张图像
感谢您的帮助
编辑:这是iOS的不是OSX
答
如果你是决心用UItableView
那么你需要:
- 请在故事板电池原型,加入5个ImageViews在位置的细胞,你想他们是
- 做一个类扩展
UITableViewCell
,将其设置在ST oryboard作为类为原型细胞,德朗和放下的ImageViews作为网点该类 -
在课堂上要使用它,你会想是这样的:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> MyCustomTablleCellWithFiveImagesInIt { let cell = tableView.dequeueReusableCellWithIdentifier("MyReusableCellID", forIndexPath: indexPath) cell.image1 = datasource[indexPath.row * 5 + 0] cell.image2 = datasource[indexPath.row * 5 + 1] cell.image3 = datasource[indexPath.row * 5 + 2] cell.image4 = datasource[indexPath.row * 5 + 3] cell.image5 = datasource[indexPath.row * 5 + 4] return cell }
,不要忘了
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return datasource.count/5
}
不过我建议你还是用UICollectionView
你是问关于iOS或Ø S X? –
iOS。谢谢你提醒我澄清一下, – user3175707
对于iOS,你可能更喜欢'UIStackView' –