reloadData() fatal error: unexpectedly found nil while unwrapping an Optional value

前端 未结 1 1513
耶瑟儿~
耶瑟儿~ 2021-01-20 00:43

The app crashes at the line \"enter

class ImageValueCell: UITabl         


        
相关标签:
1条回答
  • 2021-01-20 01:12

    If you are calling addImagesValue before the awakeFromNib is called, then your code will empty the array. I don't think that is what you want. Here is a better solution:

    class ImageValueCell: UITableViewCell, UITableViewDelegate, UITableViewDataSource {
    
        @IBOutlet weak var imagesList: UITableView!
        var imageArray: NSArray = NSArray() {
            didSet {
                // whenever the imageArray changes, reload the imagesList
                if let imagesList = imagesList {
                    imagesList.reloadData()
                }
            }
        }
    
        override func awakeFromNib() {
            // why isn't the below done from inside the nib file? That's how I would do it.
            imagesList.delegate = self
            imagesList.dataSource = self
            imagesList.reloadData()
        }
    
        func addImagesValue(objectList: NSMutableArray, machine: WIFIMachine){
            imageArray = objectList
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题