我有三個imagesviews在我看來,細胞,他們目前都顯示相同的圖像我想知道如何使每個圖像的單獨圖像,可能像 顯示兩個不同的圖像如果香蕉其他的圖像= imagebanana顯示圖像,如果蘋果的形象= imageapple顯示圖像,如目前在每個單獨的單元中的所有圖像香蕉,香蕉,香蕉,我想有香蕉,蘋果,梨在一個小區?迅速 - 如何在定製視圖細胞
struct cellData {
let cell: Int!
let text: String!
let image: UIImage!
}
class HomepageVC2JAREDTutorial: UITableViewController {
var arrayofCellData = [cellData]()
override func viewDidLoad() {
super.viewDidLoad()
arrayofCellData = [cellData(cell : 1, text : "tom",image : #imageLiteral(resourceName: "tom3")),cellData(cell : 2, text : "denis",image : #imageLiteral(resourceName: "denis2")),cellData(cell : 1, text : "mark",image : #imageLiteral(resourceName: "mark1")),]
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arrayofCellData.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if arrayofCellData[indexPath.row].cell == 1{
let cell = Bundle.main.loadNibNamed("XibCustomCellJared", owner: self, options: nil)?.first as! XibCustomCellJared
cell.ProfilePictureImageView.image = arrayofCellData[indexPath.row].image
cell.MoreOptionsImageView.image = arrayofCellData[indexPath.row].image
cell.AccountTypeImageView.image = arrayofCellData[indexPath.row].image
cell.DisplayNameLabel.text = arrayofCellData[indexPath.row].text
cell.StatusSubtitleLabel.text = arrayofCellData[indexPath.row].text
return cell
}else if arrayofCellData[indexPath.row].cell == 2{
let cell = Bundle.main.loadNibNamed("Xib2CustomCellJared", owner: self, options: nil)?.first as! Xib2CustomCellJared
cell.ProfilePictureImageView.image = arrayofCellData[indexPath.row].image
cell.MoreOptionsImageView.image = arrayofCellData[indexPath.row].image
cell.AccountTypeImageView.image = arrayofCellData[indexPath.row].image
cell.DisplayNameLabel.text = arrayofCellData[indexPath.row].text
cell.StatusSubtitleLabel.text = arrayofCellData[indexPath.row].text
return cell
}else{
let cell = Bundle.main.loadNibNamed("XibCustomCellJared", owner: self, options: nil)?.first as! XibCustomCellJared
cell.ProfilePictureImageView.image = arrayofCellData[indexPath.row].image
cell.MoreOptionsImageView.image = arrayofCellData[indexPath.row].image
cell.AccountTypeImageView.image = arrayofCellData[indexPath.row].image
cell.DisplayNameLabel.text = arrayofCellData[indexPath.row].text
cell.StatusSubtitleLabel.text = arrayofCellData[indexPath.row].text
return cell
}
}
你需要在每個對象中添加3幅不同的圖像,如果你想顯示在每個單元imageviews不同的圖像。 –
我真的還是不明白你的困難......你爲什麼不在你的struct cell中使用3張圖DataData 每個imageview有一個? –
感謝@ClaudioCastro只是因爲我現在明白了!美麗 – benpalmer661