For my dynamic prototype tableview I have 135 cells. So i created a variable array:
var myLife = Array(count: 135, repeatedValue: "My Cell")
I have a mycell.jpg that I want to display on every one of those 135 cells, but i ended up writing mycell.jpg 135 times in this array cos I only know of this way to write the array for images.
var myCellImage = ["mycell.jpg", "mycell.jpg", "mycell.jpg", "mycell.jpg",......]
Is there a better code? Can anyone help me?
You've got a method called cellForRowAtIndexPath
in your UITableView
. This method gets called for each cell.
So, in there you can set the picture once and it will be set for every cell:
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
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments