A similar question is asked here , but this does not solve this problem for me. I added tableViewin ViewController. I made an extended class with it dataSource and Delegate and added the necessary methods for it.
Then I made a prototype cell in this table (not a separate .xib for it) and made a class for this TableViewCelland put together @IBOutlet:
@IBOutlet weak var titleOfAccount: UILabel!
@IBOutlet weak var lastModified: UILabel!
@IBOutlet weak var accountImage: UIImageView!
@IBOutlet weak var cellView: UIView!
Then into cellForRowAtthe table view method when I wrote
cell.titleOfAccount.text = "Hello World"
cell.lastModified.text = "Last Modified: 21 May 2017"
and executed the code that he encountered this error.
fatal error: nil unexpectedly found while deploying optional value
, TableViewCell ! ? cellForRowAt :
cell.titleOfAccount?.text = "Hello World"
cell.lastModified?.text = "Last Modified: 21 May 2017"
, , , tableView , :
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3;
}
cellForRowAt:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: AccountsTableViewCell = self.tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier) as! AccountsTableViewCell
cell.backgroundColor = UIColor.clear
cell.clipsToBounds = true
cell.cellView.layer.shadowColor = UIColor.black.cgColor
cell.cellView.layer.shadowOpacity = 1
cell.cellView.layer.shadowOffset = CGSize.zero
cell.cellView.layer.shadowRadius = 10
cell.titleOfAccount.text = "Hello World"
cell.lastModified.text = "Last Modified: 21 May 2017"
cell.accountImage.image = UIImage(named: "fb")
return cell
}
P.S. self.tableView.register(AccountsTableViewCell.self, forCellReuseIdentifier: cellReuseIdentifier) viewDidLoad
