我TableViewCell1: UITableViewCell
類用下面的代碼:調用awakeFromNib
override func awakeFromNib() {
super.awakeFromNib()
if (gender[0] == true){
let origImage = UIImage(named: "maleP");
let tintedImage = origImage?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
genderButton[0].setImage(tintedImage, forState: .Normal)
genderButton[0].tintColor = UIColor(hex: "d8006c")
}
else{
let origImage = UIImage(named: "maleP");
let tintedImage = origImage?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
genderButton[0].setImage(tintedImage, forState: .Normal)
genderButton[0].tintColor = UIColor(hex: "333333")
}
if (gender[1] == true){
let origImage = UIImage(named: "femaleP");
let tintedImage = origImage?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
genderButton[1].setImage(tintedImage, forState: .Normal)
genderButton[1].tintColor = UIColor(hex: "d8006c")
}
else{
let origImage = UIImage(named: "femaleP");
let tintedImage = origImage?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
genderButton[1].setImage(tintedImage, forState: .Normal)
genderButton[1].tintColor = UIColor(hex: "333333")
}
}
,我就剩視圖控制器,它具有的tableview控制器,問題是,我想清除細胞內的價值,回到之前想要重新加載它..
@IBAction func clearSelection(sender: AnyObject) {
staticlink = ""
attribute1 = [String]()
values1 = [String]()
gender = [false,false]
seasons = [false,false,false,false]
clickedsection = 10
cliedkarry = [false,false,false,false,false,false,false,false]
tableView.reloadData()
}
如何我可以將我的無所作爲應用於tableview單元格或所有的tableview!
我試過tableView.reloadData(),但它沒有工作,我猜是因爲我用這種方式註冊碎粒
tableData = [
["title": "Gender", "height": "120", "cellID": "cell1"]]
tableView.registerNib(UINib(nibName: "TableViewCell1", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "cell1")
這是我cellForRowAtIndexPath
:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let record = tableData[indexPath.section];
let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(record["cellID"] as! String)!
cell.hidden = !(CBool(expandSections[indexPath.section] as! NSNumber))
return cell
}
所以我怎麼能重新加載tableview單元格內的數據
我該怎麼做:( –
ty我做到了;)它的工作 –
很高興你發現它有幫助。這也是很好的閱讀:https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html –