一開始看到會是空白一片,我們加入一個TableViewCell。


接著建立Swift File,名字為InfoCell,Class名稱也是 InfoCell:
class InfoCell : UITableViewCell{
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var detailLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
selectionStyle = .none
}
}
將MyInfoCell內的TableViewCell的Custom Class指向InfoCell。
最後,在主要的class內加入delegate,然後加入這幾行:
override func viewDidLoad() {
let myNib = UINib(nibName: "MyInfoCell", bundle: nil)
tableview.register(myNib, forCellReuseIdentifier: "myCell")
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableview.dequeueReusableCell(withIdentifier: "addressCell") as! InfoCell
}