gpt4 book ai didi

ios - 如何在 Swift 的 tableView 单元格中添加一个开关?

转载 作者:可可西里 更新时间:2023-11-01 02:28:14 26 4
gpt4 key购买 nike

我想在我的单元格中将一个开关添加到 tableView 中,但我不知道。如果我将其添加到 Storyboard 中并声明了 socket ,我会收到连接错误。我只能使用此代码添加带有参数 cell.imageView 的 ImageView,但我无法添加开关。.如何实现?

  override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
var cell:UITableViewCell! = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell!

cell.textLabel.text = self.contacts[indexPath.row]
cell.imageView.image = UIImage(named: "image")
cell.imageView.layer.borderWidth=1.0
cell.imageView.layer.masksToBounds = false
cell.imageView.layer.cornerRadius = 13
cell.imageView.clipsToBounds = true

cell.backgroundColor = UIColor.clearColor()

return cell
}

谢谢!

最佳答案

您正在使用默认的 UITableViewCell,其中设置了组件。你需要:

  1. 子类UITableViewCell
  2. 转到 Storyboard
  3. 在属性检查器中将单元格样式设置为自定义
  4. 在身份检查器中将类设置为您的自定义类
  5. dequeueReusableCellWithIdentifier 作为您的自定义类

将单元格样式设置为自定义后,您可以在 Storyboard 中添加开关和您需要的任何其他内容,并将任何 IBOutlets 和 IBAction 连接到您的 UITableViewCell 子类。

关于ios - 如何在 Swift 的 tableView 单元格中添加一个开关?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25079657/

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