swift - 在 swift 4 中将 TableView 添加到 AlertController

标签 swift xcode tableview

enter image description here

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


        let row=animals[indexPath.row]
        let cellIdentifier = "memoCell"
        var cell=tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! MemoCellTableViewCell

        if cell == nil {
            print("cell is nill")
            cell = MemoCellTableViewCell(style: .default, reuseIdentifier: cellIdentifier)
        }

        cell.name?.text="aaa"
        cell.address?.text="haha"
        return cell
    }

我有以下错误。

'无法使具有标识符 memoCell 的单元格出队 - 必须为该标识符注册一个 nib 或一个类,或者在 Storyboard中连接一个原型(prototype)单元格'

我不知道为什么。 我在 Storyboard上设置了没有错误的类,并且还正确设置了标识符

我的代码在github上 https://github.com/kotran88/iostableviewTest

请帮我解决这个问题

最佳答案

你必须在 ViewController viewDidLoad 方法中注册你的 xib/nib

    let yourCustomNib = UINib(nibName: "MemoCellTableViewCell", bundle: nil)
    self.tableView.register(yourCustomNib, forCellReuseIdentifier: "memoCell")

关于swift - 在 swift 4 中将 TableView 添加到 AlertController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47870552/

相关文章:

javafx - tableView标题的高度

swift - Swift 字典中一个键的多个值

iphone - 有没有办法找到设置了 AspectFit 的 UIImageView 内图像的调整大小高度/宽度?

ios - X代码 : Multiple Target

xcode - 在 Xcode 3.1.4 中添加 -Wall 和 -Wextra 的位置

Tableview 内的 iOS Swift 文本字段

ios - 我怎样才能快速洗牌 RLMResults ?

swift - 使用 Swift 将整数分成 double

ios - 向自定义键盘添加建议

javafx - 将 CheckBox 列添加到现有 TableView