【发布时间】:2018-12-13 09:39:50
【问题描述】:
我想在每个打开 URL 的表格单元格中包含一个按钮。
我已经创建了带有图像和标签的表格(使用数组),但是我对如何创建按钮感到困惑
这是我目前所拥有的
class ExploreCell: UITableViewCell {
@IBOutlet weak var exploreImageView: UIImageView!
@IBOutlet weak var exploreTitleView: UILabel!
@IBOutlet weak var exploreDescriptionView: UILabel!
@IBOutlet weak var exploreButton: UIButton!
func setExplore(explore: Explore) {
exploreImageView.image = explore.image
exploreTitleView.text = explore.title
exploreDescriptionView.text = explore.description
exploreButton.addTarget(self, action: "connected:", for: .touchUpInside) = explore.button
}
我的数组类如下所示
class ExploreListScreen: UIViewController {
@IBOutlet weak var tableView: UITableView!
var explores: [Explore] = []
override func viewDidLoad() {
super.viewDidLoad()
explores = createArray ()
tableView.delegate = self
tableView.dataSource = self
}
func createArray() -> [Explore] {
var tempExplores: [Explore] = []
let explore1 = Explore(image: #imageLiteral(resourceName: "test"), title: "Demo", description: "Essential", button: "")
tempExplores.append(explore1)
return tempExplores
}
我终于有了另一个包含声明变量的文件
class Explore {
var image: UIImage
var title: String
var description: String
var button: UIButton
init(image: UIImage, title: String, description: String, button: UIButton) {
self.image = image
self.title = title
self.description = description
self.button = button
}
任何建议和指导都会很棒。谢谢!
【问题讨论】:
-
您想设计按钮或在按钮点击中导航不同的网址
-
我想导航到“createArray”函数中指定的 URL。
-
在这个 URL 上了解自定义单元格:) medium.com/@aapierce0/…