提供:我的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
}
}
Run Code Online (Sandbox Code Playgroud)
删除tableviewcell类中的以下代码
/*
@IBAction func bookbtn1(_ sender: Any) {
} */
Run Code Online (Sandbox Code Playgroud)
并添加到UIviewcontroller cellForRowAtIndexPath中
cell. BookbtnOutlet.tag = indexpath.row
cell. BookbtnOutlet.addTarget(self, action: #selector(self. bookbtn1(_:)), for: .touchUpInside);
Run Code Online (Sandbox Code Playgroud)
并且在同一个UIVeiwController中的任何地方定义如下的功能
func bookbtn1(_ sender : UIButton){
// call your segue code here
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3303 次 |
| 最近记录: |