gpt4 book ai didi

ios - 自定义单元格中的按钮现在显示

转载 作者:行者123 更新时间:2023-11-28 11:22:00 25 4
gpt4 key购买 nike

我已经开始学习如何在 swift 中为 iOS 编码,在我的应用程序中我尝试使用带有自定义 cels 的表格 View ,单元格中有四个标签和两个按钮,我的问题是按钮和两个标签不是由于某种原因,我检查了一些教程并搜索了 stackoverflow,但找不到我的问题的任何答案。这是我的 Storyboard的样子:enter image description here

这是我的 CustomCell 类:

import UIKit

class CustomCell: UITableViewCell {


@IBOutlet weak var numberVehicle: UILabel!
@IBOutlet weak var nameVehicle: UILabel!
@IBOutlet weak var showHideButton: UIButton!
@IBOutlet weak var focusButton: UIButton!
@IBOutlet weak var hideLabel: UILabel!
@IBOutlet weak var focusLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}

override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state
}

}

这是 Controller 中 tableView 函数的代码:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("CustomCell", forIndexPath: indexPath) as CustomCell
let key = indexPath.row
let vehicle = vehicles[key]
let image = UIImage(named: "button.png") as UIImage?
cell.nameVehicle.text = vehicle.name
cell.numberVehicle.text = vehicle.number
cell.showHideButton.setBackgroundImage(image, forState: .Normal)
cell.focusButton.setBackgroundImage(image, forState: .Normal)

return cell
}

这是它在 iOS 模拟器中的样子:enter image description here任何帮助将不胜感激

最佳答案

你能在 Storyboard底部布局中试试这个吗?但首先要确定

use Auto Layout

勾选。

enter image description here

关于ios - 自定义单元格中的按钮现在显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27144081/

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