我想在自定义表格的按钮中填充标签。一切正常,除了我不知道如何将我的 IBAction
函数的计算数据发送回 UITableView
函数,以便它通过 return cell< 显示
声明。
请看代码和下面代码中的注释:
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak
var lblHeader: UILabel!
@IBOutlet weak
var tableView: UITableView!
var players: NSMutableArray! = NSMutableArray()
override func viewDidLoad() {
super.viewDidLoad()
self.players.addObject("Hannah")
self.players.addObject("Katie")
self.players.addObject("Ashley")
self.players.addObject("Kate")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) - > Int {
return self.players.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) - > UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as!CustomCell
cell.plrZeroes.tag = indexPath.row
cell.plrZeroes.addTarget(self, action: "plrOnesAction:", forControlEvents: .TouchUpInside)
return cell
}
@IBAction func plrOnesAction(sender: UIButton!) {
let pAvg = self.players.objectAtIndex(sender.tag) as ? String
** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *
HERE I WANT TO SEND “pAvg” BACK TO THE CALLER SO I CAN INCLUDE IT IN THE “return cell” LINE OF THE TABLEVIEW FUNCTION
** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *
}
}
最佳答案
您可以使用索引路径获取单元格
让 cell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: sender.tag, inSection:0))
关于ios - 将值返回给 tableView 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35401510/