ios - 将值返回给 tableView 函数

标签 ios swift

我想在自定义表格的按钮中填充标签。一切正常,除了我不知道如何将我的 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/

相关文章:

ios - 如何查看变量的值是否为Nil

ios - 如何关闭模态呈现的 UINavigationController?

ios - 如何根据图像类别从 firebase 存储中检索图像(例如汽车、抽象)

ios - 退出代码 1 的随机错误 - Xcode 6.1 Swift

ios - 使用 UISplitViewController 的多个 DetailViewController

IOS 根据 NSMutableArray 值更改 Uitableview 中的 Accessory View Cell Image

ios - 如何在 UIImageView (Swift) 中显示来自 Parse 的图像?

ios - Swift:如何让 UIScrollView ClipsToBounds 仅水平工作。

ios - 如何使用 MDCTabBar

ios - ViewModel函数: Cannot assign to value: 'error' is a 'let' constant