鍍金池/ 問(wèn)答/iOS/ uitableview點(diǎn)擊cell高亮但是不執(zhí)行didSelectRowAt i

uitableview點(diǎn)擊cell高亮但是不執(zhí)行didSelectRowAt indexPath

代碼如下

點(diǎn)擊可以高亮顯示,但是不走didSelectRowAt indexPath的方法。

//
//  menuViewController.swift
//  record
//
//  Created by 郭 on 2018/5/26.
//  Copyright ? 2018年 郭. All rights reserved.
//

import UIKit

class MenuViewController: UIViewController ,UITableViewDataSource, UITableViewDelegate{
    var table:UITableView!
    let bgColor = UIColor.init(red: 45/255, green: 50/255, blue: 53/255, alpha: 1)
    let arry:[String] = ["列表", "2", "3"]
    var changeView:changeViewDelegate? = nil
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = bgColor
        self.setUpLayout()
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    func setUpLayout(){
        let rect = self.view.frame
        self.table = UITableView(frame: CGRect(x: 0, y: 63, width: rect.width, height: rect.height-62))
        self.table.backgroundColor = bgColor
        self.table.dataSource = self
        self.table.separatorStyle = UITableViewCellSeparatorStyle.none
        self.table.rowHeight = 100
        self.table.allowsSelection = true;
        self.view.addSubview(self.table)
        
    }

    func  rowChangeView() {
        print("adf")
        
    }
    //    列表代理方法
    
    //設(shè)置cell的數(shù)量
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return arry.count
    }
    
    //設(shè)置section的數(shù)量
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        return true
    }
    public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
        print("indexPath.row = SelectRow第\(indexPath.row)行")
    }
    //設(shè)置tableview的cell
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let rect = self.view.frame
        let cell = UITableViewCell.init(frame: CGRect(x: 0, y: 0, width: rect.width, height: 100))
        cell.backgroundColor = bgColor
        let indexLabel = UILabel.init(frame: CGRect(x: 23, y: 16, width: rect.width, height: 20))
        indexLabel.textColor  = UIColor.white
        indexLabel.text = arry[indexPath.row]
        cell.addSubview(indexLabel)
        
        return cell
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
回答
編輯回答
筱饞貓

table.delegate = self 少了這個(gè)

2018年4月27日 17:42
編輯回答
扯機(jī)薄

tableview少了個(gè)代理?

2017年11月12日 17:19