Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use swift inner class on Interface Builder

Tags:

xcode

ios

swift

I have an inner custom UITableViewCell class (class inside a class), I would like to use it in Interface Builder. However, it can't recognize it there.

import UIKit

class ContactListViewController: UIViewController {
    class Cell: UITableViewCell {
        @IBOutlet weak var name: UILabel!
        @IBOutlet weak var phone: UILabel!
    }
    
    @IBOutlet weak var tableView: UITableView!
}

screenshot

The configuration of above image didn't work. Is there a way to do it?

like image 963
Howard Avatar asked Feb 24 '16 07:02

Howard


1 Answers

You need to specify objective c name for your nested class with @objc then use it in the Interface Builder:

import UIKit

class ContactListViewController: UIViewController {
    @objc(CLCell) class Cell: UITableViewCell {
        @IBOutlet weak var name: UILabel!
        @IBOutlet weak var phone: UILabel!
    }

    @IBOutlet weak var tableView: UITableView!
}

enter image description here

like image 191
MuHAOS Avatar answered Nov 13 '22 00:11

MuHAOS