I would like to change the text of a button that was declared in a separate class/file. The button shows as nil in the referencing function (which is in a separate file). Please show me any code necessary to change the value of btnCounter to "0" of the IBOUTLET from "FILE TWO". Thank you
/* THIS IS FILE ONE */
import UIKit class CustomCell: UITableViewCell {
@IBOutlet weak var btnCounter: 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
}
}
/****** THIS IS FILE TWO ******/
import UIKit
import CoreData
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate
{
override func viewDidAppear(animated: Bool){
}
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
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.btnCounter.titleLabel?.text = (myArray[indexPath.row])
return cell
}
func displayResetAlertMessage(userMessage:String) {
let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert)
let destructiveAction = UIAlertAction(title: "Yes, Delete All Data", style: UIAlertActionStyle.Destructive){(ACTION)in print("Delete Button Tapped")
/******** THIS IS WERE I TRY TO REFERENCE THE BUTTONS IN “Custom Cell” ******/
var newCellClass = CustomCell()
/* THE VAULE OF custCellClass.btnCounter TURNS OUT TO BE “nil” BEFORE AND AFTER THE STATEMENT IS EXECUTED. THIS IS WHERE I NEED HELP TO CHANGE THE VALUE OF THE IBOUTLET IN "FILE ONE" TO btnCounter TO "0" */
custCellClass.btnCounter?.setTitle("0", forState: .Normal)
}
let cancelAction = UIAlertAction(title: "No, Just Leave it Alone and Return", style: UIAlertActionStyle.Default, handler: nil)
myAlert.addAction(destructiveAction)
myAlert.addAction(cancelAction)
self.presentViewController(myAlert, animated:true, completion:nil)
}