问题
I have a class:
class ListOfEventsController: UIViewController, UITableViewDataSource, UITableViewDelegate {
and it contains a function:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("CELL") as! SingleEventCell
and when I run it - it causes an error that says
fatal error: unexpectedly found nil while unwrapping an Optional value
but when I go to my story board I see:
and when I click CELL
I see in its properties:
and also:
so the identifiers for CELL
are set up, but I'm still getting this error.
What else can I do?
回答1:
- In Storyboard select your prototype cell
- alt + cmd + 4 to open the Attribute Inspector
- Write
CELL
into theIdentifier
field.
Then try again ;)
回答2:
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"CELL"];
For your problem.
回答3:
Try
let cell = tableView.dequeueReusableCellWithIdentifier("CELL", forIndexPath: indexPath) as! SingleEventCell
来源:https://stackoverflow.com/questions/35535791/swift-and-unexpectedly-found-nil-while-unwrapping-an-optional-value