Is there any way I can access the buttons and labels that were defined in Custom Cell from my viewController.swift file? I want to access the text of all the other buttons and set the text of the "plrAvg" all within the "handleButtonPressed" function (see the function in the code below).
import UIKit
class CustomCell: UITableViewCell {
@IBOutlet weak var plrNumber: UILabel!
@IBOutlet weak var plrAvg: UILabel!
@IBOutlet weak var btn1: UIButton!
@IBOutlet weak var btn2: UIButton!
@IBOutlet weak var btn3: UIButton!
@IBOutlet weak var btn4: UIButton!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var lblHeader: UILabel!
@IBOutlet weak var tableView: UITableView!
/******* Establish Variables *******/
var players: NSMutableArray! = NSMutableArray()
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 6
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomCell
// Poputate the players //
cell.plrNumber.text = (players[indexPath.row] as! String)
// add a line for each one of the buttons
cell.btn1.addTarget(self, action: "handleButtonPressed:", forControlEvents: .TouchUpInside)
cell.btn2.addTarget(self, action: "handleButtonPressed:", forControlEvents: .TouchUpInside)
cell.btn3.addTarget(self, action: "handleButtonPressed:", forControlEvents: .TouchUpInside)
cell.btn4.addTarget(self, action: "handleButtonPressed:", forControlEvents: .TouchUpInside)
return cell
}
// ***********************************
@IBAction func handleButtonPressed(sender:UIButton!)
{
************************************************************
IS THERE ANY CODE THAT WOULD ALLOW ME TO ACCESS ALL THE OTHER BUTTONS (btn1, btn2, btn3, btn4) AS WELL AS THE LABEL (plrAvg)
************************************************************
switch sender.tag {
case 0:
print(sender.tag)
case 1:
print(sender.tag)
case 2:
print(sender.tag)
case 3:
print(sender.tag)
default:
print("Tag was not found")
}
}
}