【发布时间】:2018-08-04 19:53:38
【问题描述】:
如何检测UITableviewCell 中的一个按钮,我在UITableViewCell 中有10 个UIButton,接下来当我点击UIButton 时它会检测到多个按钮,(就像奇数列表一样)。我的UITableView 启用了分页。这是我的所有代码。
表格视图
class HomeViewController: UIViewController, UITableViewDelegate,UITableViewDataSource {
@IBOutlet weak var homeTableView: UITableView!
let mainArray = [["1","2","3","4"],["5","6","7","8"],["9","10","11","12"],["13","14","15","16"]]
override func viewDidLoad() {
super.viewDidLoad()
self.homeTableView.delegate = self
self.homeTableView.dataSource = self
}
func numberOfSections(in tableView: UITableView) -> Int {
return mainArray.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return mainArray[section].count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "HomeTableViewCell", for: indexPath) as! HomeTableViewCell
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return self.view.frame.size.height
}
}
TableViewCell
class HomeTableViewCell: UITableViewCell {
@IBOutlet weak var bookMarkBtn: UIButton!
@IBAction func bookMarkBtnAction(_ sender: UIButton) {
sender.isSelected = !sender.isSelected
if(sender.isSelected == true)
{
sender.setImage(UIImage(named:"favorite_blue"), for: UIControlState.normal)
}
else
{
sender.setImage(UIImage(named:"favorite_white"), for: UIControlState.normal)
}
}
}
【问题讨论】:
-
您能否附上视图的屏幕截图,并说明您所说的“它检测到多个按钮,(如奇数列表)”。
-
@Sam 我没有足够的积分所以无法截图
-
@Sam 给我邮件地址然后我把项目发给你
-
你可以添加截图,但它不会嵌入图片内联,它只会让你添加链接。
-
@Sam 请提供链接。我在哪里添加屏幕截图
标签: ios swift uitableview uibutton