简体   繁体   中英

Use swift inner class on Interface Builder

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

import UIKit

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

    @IBOutlet weak var tableView: UITableView!
}

在此输入图像描述

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

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!
}

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM