This is my goal: When the Start
button is tapped, I want the Send
buttons to be enabled. The following is what my view controller looks like when loaded:
As you can see, the Send
buttons are disabled, which is desired. And I've disabled it by writing the following code in my TaskListTableViewCell.swift
(I deleted some other irrelevant code for the sake of being succinct):
class TaskListTableViewCell: UITableViewCell {
@IBOutlet weak var sendButton: UIButton!
override func awakeFromNib() {
super.awakeFromNib()
sendButton.enabled = false
}
}
And just in case it might help you see better, this is how the view controller looks like in the Main.storyboard
:
And in my TaskListViewController
, I have the following code:
@IBAction func startButtonTapped(sender: AnyObject) {
//write the code here to change sendButton.enabled = true
}
The problem is, I cannot seem to find a way to change the sendButton.enabled = true
. I've tried:
@IBAction func startButtonTapped(sender: AnyObject) {
let taskListViewController = TaskListViewController()
taskListTableViewCell.sendButton.enabled = true
}
I've also tried:
class TaskListTableViewCell: UITableViewCell {
@IBOutlet weak var sendButton: UIButton!
func changeSendButtonEnabled() {
sendButton.enabled = true
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
sendButton.enabled = false
}
}
And in my TaskListViewController.swift
, I wrote:
@IBAction func startButtonTapped(sender: AnyObject) {
let taskListViewController = TaskListViewController()
taskListTableViewCell.changeSendButtonEnabled()
}
But both of these solutions give this error: fatal error: unexpectedly found nil while unwrapping an Optional value
.
I've read some other posts about accessing an IBOutlet from another class such as this post: How to access an IBOutlet from another class, Accessing IBOutlet from another class, Access an IBOutlet from another class in Swift, and using IBOutlet from another class in swift. However, none of these posts were able to solve my problem.