Hello,
Sorry i placed it in the wrong forum. the way this ui works is still unfamiliar to me if I don't know the valid forums that are available. I know to put it in swift next time as this is a swift programming language issue.
I've been learning how to do tableviews.
I have implemented a custom tableviewcell on a view which is part of my main screen and it's controller.
I've implemented methods for the datasource and delegate
this is the main code of the datasource function.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath) as! PanicAlertTableViewCell
let sender = sender_list[indexPath.row]
let number = indexPath.row
let count = String.localizedStringWithFormat("%I)", number)
print(sender_list[number])
cell.selectionStyle = UITableViewCellSelectionStyle.none
if sender.is_sound == "0" {
cell.btnOff.isHidden = true
}
cell.delegate = self
cell.set(number: count, alert: sender.name, indexPath: indexPath)
return cell
}these are the other 2 functions used with the tableview
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
NSLog("Counting rows")
return sender_list.count
}func numberOfSections(in tableView: UITableView) -> Int {
return 1
}Here is the class in question:
class PanicAlertTableViewCell: UITableViewCell {
public var delegate : PanicAlertTableViewCellDelegate?
var indexPath: IndexPath?
@IBOutlet weak var lblNumber: UILabel!
@IBOutlet weak var lblAlert: UILabel!
@IBOutlet weak var btnOff: UIButton!
func set(number: String, alert: String, indexPath: IndexPath) {
self.lblNumber.text = number
self.lblAlert.text = alert
self.indexPath = indexPath
}
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
}
@IBAction func btnOff(_ sender: UIButton) {
if (indexPath != nil && delegate != nil) {
delegate!.panicButtonClicked(cell: self, indexPath: indexPath!)
}
}
}sender_list is an array of PanicSender objects however the number items in this array are always changing, so i run the reloadData method on the tableview.
however when it goes to set the number and name with the labels in the cell it crashes with BAD_EXC_INSTRUCTION
I learnt that the cell itself has to have an identifier. this identifier is PanicIdentifier.
however it doesn't load the awakeFromNib function (I have a breakpoint on the function but the program never stops)
All three components are connected with the storyboard.
I imagine i'm just missing something as this is my first time using tableviews.
It appears as though there are some solutions but feel like i'm following a rabbit hole. I've looked at these articles:
https://stackoverflow.com/questions/20725151/how-to-properly-init-a-custom-uitableviewcell
https://stackoverflow.com/questions/29321383/iboutlet-is-nil-but-it-is-connected-in-storyboard-swift
Thanks for any help in advance!