0
//该objectsAry是NSManagedObjects编程方式更改按钮图像中的表格单元格
//main view controller
var nowImg = UIImage(named: "img30.png")
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var NuTblCellInst = NuTableViewCell()
var maincell:UITableViewCell = self.mainList.dequeueReusableCellWithIdentifier("maincell") as NuTableViewCell
maincell.textLabel.text = self.objectsAry[indexPath.row].valueForKey("itemname") as? String
//NuTblCellInst.doImgLoad(nowImg!)
//uncomment the line above = fatal error: unexpectedly found nil while unwrapping an Optional value
// it doesn't matter if i use the method or use NuTblCellInst.btnWImg.setBackgroungImage directly (unwrapping error either way)
return maincell
}
// custom tableview cell class
class NuTableViewCell: UITableViewCell {
@IBOutlet weak var btnWImg: UIButton!
var nowImg = UIImage(named: "img30.png")
func doImgLoad(theImg: UIImage) {
btnWImg.setBackgroundImage(theImg, forState: UIControlState.Normal)
}
override func awakeFromNib() {
super.awakeFromNib()
//doImgLoad(nowImg!)
//uncomment the line above and it loads the image to the button no problem
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
我填充一个可重复使用的盒W /文本如上,但不知道如何访问图像(或背景图像),放置在表格单元格中的按钮,使用故事板,其中图像随表格行而变化。
会回来。可能还要等一下。那么,如果我已经返回maincell,如何返回CFRAIP中的自定义类实例? – agent86 2014-11-04 21:20:39
你的CFRAIP现在是什么样的? – 2014-11-04 21:46:52
新增了解答的更多详细信息 – 2014-11-04 22:45:40