繁体   English   中英

Swift 3.0中的UIButton问题

[英]Uibutton issue in swift 3.0

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    var cell = UITableViewCell()

    if isFacility {
        cell = tableView.dequeueReusableCell(withIdentifier: "facilityCell")!
        let gameNameLbl = cell.viewWithTag(100) as! UILabel
        gameNameLbl.text = "Badminton Court"
        let gameImgVw = cell.viewWithTag(101) as! UIImageView
        let bookNowBtn = cell.viewWithTag(102) as! UIButton
        bookNowBtn.backgroundColor = DEFAULTAPPCOLOR
        ConstantFile.makeCornerRoundBtnWithOutBorder(btn: bookNowBtn)
        bookNowBtn.tag = indexPath.row
        bookNowBtn.addTarget(self, action: #selector(bookCort(sender:)), for: .touchUpInside)


        bookNowBtn.setTitle("BOOK NOW", for: .normal)
        if indexPath.row % 2 == 0 {
            gameImgVw.backgroundColor = UIColor.red
        }
        else{
            gameImgVw.backgroundColor = UIColor.darkText
        }
    }
    else{
        cell = tableView.dequeueReusableCell(withIdentifier: "bookingCell")!
        let gameImgVw = cell.viewWithTag(103) as! UIImageView
        let gameNameLbl = cell.viewWithTag(104) as! UILabel
        let gameDateLbl = cell.viewWithTag(105) as! UILabel
        let gametimeLbl = cell.viewWithTag(106) as! UILabel
        ConstantFile.roundImageViewWithOutBorder(image: gameImgVw)
        gameNameLbl.text = "Tennis Court"
        gameDateLbl.text = "22 Dec 2017"
        gametimeLbl.text = "7:00pm - 9:00pm"
    }
    return cell

}

在上面的代码中,滚动uibutton的表“致命错误:在打开可选值时意外发现nil”使我崩溃(在这一行中,让bookNowBtn = cell.viewWithTag(102)作为UIButton)。

可能您在StoryBoard中设置了不同的标签值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM