>我有一个UITableView,里面有一个UITableViewCell,里面有一个文本视图和图像视图
在我定义的快速文件中
class NotificationCell: UITableViewCell {
@IBOutlet weak var notificationAvatarImage: UIImageView!
@IBOutlet weak var notificationText: UITextView!
override func awakeFromNib() {
notificationAvatarImage.clipsToBounds = true
notificationAvatarImage.contentMode = .scaleAspectFill
}
}
我无法将情节提要中的图像视图和文本视图连接到IBOutlet通知头像图像...在通知单元格中。我该怎么做?
我正在加载表
guard let notificationCell = tableView.dequeueReusableCell(withIdentifier: "Cell") as? NotificationCell else {
fatalError("Error getting cell")
}
首先使用 tableview 的UITableViewDataSource
委托来加载 tableviewcell。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! NotificationCell
return cell
}
使用情节提要
现在在情节提要中创建 UITableViewCell 并将该 UITableViewCell 的Class
设置为NotificationCell
然后右键单击情节提要中表视图单元格的图像视图和文本视图,并将其分配给您在 Swift 中编写NotificationCell
类的@IBOutlet