gpt4 book ai didi

ios - 在 Swift 中连接 UITableViewCell 标签

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:26:50 26 4
gpt4 key购买 nike

我有一个 TableView Cell,里面有一个 ImageViewLabel。但是当我使用以下方式连接到他们时:

 @IBOutlet weak var menuListLabel: UILabel!
@IBOutlet weak var menuListImage: UIImageView!

enter image description here

Illegal Configuration:

The menuListImage outlet from the ViewController to the UIImageView is invalid. Outlets cannot be connected to repeating content.

最佳答案

您需要创建一个继承自 UITableViewCell 的自定义类,并在那里配置 socket 。

class MyCustomTableViewCell: UITableViewCell {
@IBOutlet weak var menuListLabel: UILabel!
@IBOutlet weak var menuListImage: UIImageView!
}

接下来,您需要在 Storyboard中配置单元格。选择您的手机。打开身份检查器并将自定义类设置为“MyCustomTableViewCell”。

然后,在单元格仍处于选中状态的情况下,转到属性检查器,并将重用标识符设置为“MyCustomTableViewCell”。 (这个标识符可以是任何你想要的,你只需要在调用'dequeueReusableCellWithIdentifier'时使用这个确切的值。我喜欢使用我的单元格的类名作为标识符,这样很容易记住。)

在您的 TableView Controller 中,实现必要的方法以使用您的自定义单元格构建您的表。

func numberOfSectionsInTableView(tableView: UITableView) -> Int {

return 1 // however many sections you need
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return 1 // however many rows you need
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

// get an instance of your cell
let cell = tableView.dequeueReusableCellWithIdentifier("MyCustomTableViewCell", forIndexPath: indexPath) as MyCustomTableViewCell

// populate the data in your cell as desired
cell.menuListLabel.text = "some text"
cell.menuListImage.image = UIImage(named: "some image")

return cell
}

关于ios - 在 Swift 中连接 UITableViewCell 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27586435/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com