Patrick Bassut
Patrick Bassut

Reputation: 3338

Trying to subclass UITableViewCell on Swift

I have a problem when trying to subclass UITableViewCell and creating a xib file that correspond to this class X I have. The steps I did was the same as always.

  1. Created a XIB files that has only a UITableViewCell in it and this widget is conformed to my class X.
  2. Created a new .swift file that actually defines the X class, subclassing and everything
  3. then instantiated the class like this:

    var cell = X()

    It craches right there. My traceback looks like this traceback

I don't have a clue of what this is.

Any help?

EDIT:

The only thing I see in the console at the time of the crash is this:

2014-06-24 04:06:51.715 ChemConverter[2261:94363] SetAppThreadPriority: setpriority failed with error 45

which I don't think it's relevant.

EDIT 2:

Declared cell like this

var cell: UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(identifier) as? UITableViewCell

and it worked!

Upvotes: 1

Views: 570

Answers (1)

BJ Miller
BJ Miller

Reputation: 1548

Without an error message or much code to go by, what would happen if you declared your cell variable as optional? Would it crash then? Also, shouldn't you use dequeueReusableCellWithIdentifier(...) to get a reference to your cell?

Upvotes: 1

Related Questions