加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 滚动单元格时UITableView不滚动

发布时间:2020-12-14 17:25:35 所属栏目:百科 来源:网络整理
导读:我在故事板中的UIViewController中创建了一个UITableView,并创建了自定义的tableViewCell类.现在当我运行我的项目时, 当我触摸任何单元格并向上/向下移动时,它不会滚动. 但是,如果我开始使用UItableViewCell的任一端滚动(几乎是左边的15px),它会滚动. 我试图
我在故事板中的UIViewController中创建了一个UITableView,并创建了自定义的tableViewCell类.现在当我运行我的项目时,

>当我触摸任何单元格并向上/向下移动时,它不会滚动.
>但是,如果我开始使用UItableViewCell的任一端滚动(几乎是左边的15px),它会滚动.

我试图创建另一个新的tableView,仍然无法正常工作.

我试图创建一个tableViewController,仍然无法正常工作.

然后我认为代码不是问题的原因.
使用Xcode 8.2.1

以下是我的代码工作:

类文件

struct Quote {
    var text: String
}

class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {

    @IBOutlet var tableView: UITableView?

    let cellIdentifier = "cell"

    // Array of strings for the tableView

    var tableData = [Quote(text: "zadz ad azd azds fsd gdsfsd"),Quote(text: "zakd gqsl jdwld bslf bs ldgis uqh dm sd gsql id hsqdl sgqhmd osq bd zao mos qd"),Quote(text: "azdhsqdl sb ljd ghdlsq h ij dgsqlim dhsqihdùa dbz ai ljsm oqjdvl isq dbvksqjld"),Quote(text: "dsqb jhd gs qdgsq dgsq u hdgs qli hd gsql i dgsq li dhs qij dhlqs dqsdsd.")]

    override func viewDidLoad() {

        super.viewDidLoad()

        self.tableView?.register(UITableViewCell.self,forCellReuseIdentifier: self.cellIdentifier)

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    func tableView(_ tableView: UITableView,numberOfRowsInSection section: Int) -> Int {

        // Return number of rows in table

        return tableData.count
    }

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

        // Create Resusable Cell,get row string from tableData

        let cell = tableView.dequeueReusableCell(withIdentifier: self.cellIdentifier)! as! cellClass

        let row = indexPath.row

        // Set the labels in the custom cell
        cell.mainText.text = tableData[row].text

        return cell
    }

    func tableView(_ tableView: UITableView,didSelectRowAt indexPath: IndexPath) {

        // Do what you want here

        let selectValue = self.tableData[indexPath.row]

        print("You selected row (indexPath.row) and the string is (selectValue)")
    }  
}

这是我的cellClass :(自定义单元格)

class cellClass: UITableViewCell {

    @IBOutlet weak var mainText: UILabel!

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

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

        // Configure the view for the selected state
    }
}

UITableView的故事板层次结构

main.storyboard

解决方法

你可能会遇到一些x-code问题,因为通常它永远不会发生,我运行你的项目它正常工作,因为它通常工作.

以下是我所做的代码工作.

我不像你那样采用阵列结构,我只是采用简单的数组.

我的阵列是

arrayData = ["One","Two","three","four"]

下面是cellForRow

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

    let cell : cellClass = tableView.dequeueReusableCell(withIdentifier: "Cell",for: indexPath) as! cellClass
    cell.lblstates.text = arrayData[indexPath.row]
    return cell
}

如果您遇到任何问题,请告诉我.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读