1
我有一個帶有自定義單元格構建的表格視圖,自定義單元格有兩個標籤和一個文本框。當用戶編輯文本字段時,label2在當前單元格中發生變化。但我希望第二個單元格中的值(Label2)也將根據當前單元格中的值進行更改。例如:第一個單元格中的值是x,第二個單元格中的值應該是2 + x。我應該如何認識到這一點?在我的視圖控制器我使用下面的代碼:根據另一個單元格中的值更改自定義單元格中的值
var myString = [String]()
@IBOutlet weak var TableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
myString = ["a", "b"]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return myString.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CalculationsTableViewCell
tableView.tableFooterView = UIView(frame: CGRectZero) //hide empty cells in UITableView
cell.Label?.text = myString[indexPath.row]
return cell
}
我TableViewCell:
@IBOutlet weak var Label: UILabel!
@IBOutlet weak var Label2: UILabel!
@IBOutlet weak var TextField: UITextField!
@IBAction func TextFieldEditingChanged(sender: AnyObject) {
var value: Double
value = NSString(string: TextField.text!).doubleValue
Label2.text = "\(value)"
}
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}