【发布时间】:2017-09-19 11:16:05
【问题描述】:
提供:我的 xib 中有一个按钮 还附上了与此相关的 swift 文件。
问题:此单元格有一个按钮,需要在单击按钮时显示 ViewController。此单元格附加到另一个 ViewController 中的表视图。我想在“BOOK”按钮上实现一个动作,以便单击新的视图控制器应该打开。我无法做到这一点,任何人都可以建议我应该做些什么吗?
代码:
import UIKit
class HotelBookingCell: UITableViewCell {
@IBOutlet weak var BookbtnOutlet: UIButton!
override func awakeFromNib() {
super.awakeFromNib()
BookbtnOutlet.layer.cornerRadius = 7
// Initialization code
}
@IBAction func bookbtn1(_ sender: Any) {
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
【问题讨论】:
-
在你的 UIviewcontroller 中调用这个
bookbtn1, -
在您的 VC 中,在 cellforrowatindex 方法中在按钮上添加目标
-
你能出示一下代码
cellforrowatindex -
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 5; } public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cellid", for: indexPath) as! BookHotellCell 返回单元格 } @Anbu.Karthik