Arrays 如何编写swift数组,使所有动态单元格显示相同的UIImage?
对于我的动态原型tableview,我有135个单元格。所以我创建了一个变量数组:Arrays 如何编写swift数组,使所有动态单元格显示相同的UIImage?,arrays,uitableview,swift,uiimage,Arrays,Uitableview,Swift,Uiimage,对于我的动态原型tableview,我有135个单元格。所以我创建了一个变量数组: var myLife = Array(count: 135, repeatedValue: "My Cell") 我有一个mycell.jpg,我想显示在这135个单元格中的每一个单元格上,但我最终在这个数组中写入了mycell.jpg 135次,因为我只知道这样写图像数组的方法 var myCellImage = ["mycell.jpg", "mycell.jpg", "mycell.jpg", "myce
var myLife = Array(count: 135, repeatedValue: "My Cell")
我有一个mycell.jpg,我想显示在这135个单元格中的每一个单元格上,但我最终在这个数组中写入了mycell.jpg 135次,因为我只知道这样写图像数组的方法
var myCellImage = ["mycell.jpg", "mycell.jpg", "mycell.jpg", "mycell.jpg",......]
有更好的代码吗?有人能帮我吗?在UITableView中有一个名为CellForRowatineXpath的方法。每个单元格都会调用此方法 因此,您可以在其中设置图片一次,并为每个单元格设置:
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
var cell = tableView.dequeueReusableCellWithIdentifier("YourCellIdentifier") as? UITableViewCell
if cell == nil {
cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "YourCellIdentifier")
}
cell.imageView = UIImage(named: "mycell.jpg")
return cell
}
每个单元格行上始终有相同的图像?在func tableView\utableview:UITableView中,cellForRowAtIndexPath:nsindepath->UITableViewCell,在您出列的单元格上,myCell.imageView=uiimagename:myCell.jpg