如何在没有选择的情况下访问单元格表视图并将其更改为另一个类?

时间:2017-09-21 15:30:19

标签: ios uitableview swift3 cell

我有两个页面,一个是Map,第二个是List表视图

enter image description here enter image description here

正如您在地图页面中看到的,有两个按钮

1 - 如果我点击其中一个按钮,则显示一个弹出窗口

enter image description here

2-如果点击确定,背景将为黄色

enter image description here

3-在我的列表中,同一文本也是黄色。

enter image description here

如果点击右侧的绿色按钮,每个单元格都将为黄色。

我正在做所有这些(使用 Swift 3 ),除了阶段3

换句话说,我想在地图页面点击弹出窗口的确定按钮,然后在列表页面表视图中更改同名文件的单元格。

我想,我可以访问任何单元格,但我不知道,怎么做!

如果你认为另一种方法,推荐我。

我的表视图类:

import UIKit

class StudentListVC: UIViewController,UITableViewDelegate, UITableViewDataSource {

    let students: [String] = ["Blue Hacker","Black Hacker","White Hacker","Brown Hacker","Blue Hacker"]

    @IBOutlet var tableView: UITableView!


    // create a cell for each table view row
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CardCellVC

        // Configure the cell...
        cell.studentNameLabel.text = students[indexPath.row]
        cell.backgroundColor = UIColor.clear

        print("row is \(indexPath.row)")        

        return cell
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.students.count
    }



}

和我的细胞分类:

导入UIKit

class CardCellVC: UITableViewCell, UITableViewDelegate {


    @IBOutlet var container: UIView!
    @IBOutlet var studentNameLabel: UILabel!
    @IBOutlet var leftButton: UIButton!
    @IBOutlet var rightButton: UIButton!


    let containerHeight = 60.0
    let studentLabelHeight = 60.0 - 20.0
    let buttonSize = 20.0
    let yCard = 0.0

    var studentListVC = StudentListVC()

    override func awakeFromNib() {
        super.awakeFromNib()

        //// Initialization code
        let wids = studentListVC.view.frame.width

        container.frame = CGRect(x: 10.0, y: yCard, width: Double(wids-20.0), height: containerHeight)
        container.tag = 0
        container.dropShadow()

        studentNameLabel.frame = CGRect(x: 50.0, y: containerHeight/2-studentLabelHeight/2, width: Double(container.frame.width)-100, height: studentLabelHeight)
        studentNameLabel.tag = 5

        leftButton.frame = CGRect(x: 10.0, y: containerHeight/2-buttonSize/2, width: buttonSize, height: buttonSize)
        leftButton.tag = 1
        rightButton.frame =  CGRect(x: Double(container.frame.width)-10.0-buttonSize, y: containerHeight/2-buttonSize/2, width: buttonSize, height: buttonSize)
        rightButton.tag = 10

        rightButton.addTarget(self, action: #selector(CardCellVC.tapOk), for: .touchUpInside)
        leftButton.addTarget(self, action: #selector(CardCellVC.tapCancel), for: .touchUpInside)


    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

    }
@objc private func tapCancel(){
        //
        studentNameLabel.backgroundcolor = UIColor.yellow
    }


    @objc private func tapOk(){
        //
        studentNameLabel.backgroundcolor = UIColor.white
    }

0 个答案:

没有答案