Swift:未按indexPaths的顺序调用cellForRowAtIndexPath [英] Swift: cellForRowAtIndexPath not called in the order of indexPaths

查看:135
本文介绍了Swift:未按indexPaths的顺序调用cellForRowAtIndexPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,按0,1,2 ...的顺序调用indexpath ...,但是在单击表视图后,将使用似乎完全随机的indexpath调用func tablview,因此我无法重现相同的数据。我正在使用数组来关联表的行。

At first the indexpath are called in sequence of 0,1,2... but after clicking on the table view , the func tablview is called with indexpath that seems completely random , and hence i am unable to reproduce the same data . I am using array to correlate the rows of the table .

代码在这里:

// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView!) -> Int {
    // #warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1
}


override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete method implementation.
    // Return the number of rows in the section.
    return  myList.count
}
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
// Configure the cell...

    println("table view --> ")
    let CellID : NSString = "Cell"
    var cell : UITableViewCell = tableView?.dequeueReusableCellWithIdentifier(CellID)as UITableViewCell
     var VehicleName = cell.viewWithTag(1) as UILabel
     var VehicleNumber = cell.viewWithTag(2) as UILabel

     if let ip = indexPath
     {

        VehicleName.text = arrayData[ip.row*2];
        VehicleNumber.text = arrayData[ip.row*2+1];
    }
 }
     return cell

 }


推荐答案

绝对不能保证indexPaths cellForRowAtIndexPath 的调用顺序。它位于UIKit框架上。

There is absolutely no guarantee in what order of indexPaths cellForRowAtIndexPath gets called. It is upon the UIKit framework.

您需要并且可以完全控制数据源数组保存数据的方式。在这种情况下,它是 arrayData -我也觉得这在某种程度上与 myList 有关,但是从您的代码段中看不到它。研究如何在arrayData中安排元素,然后在所有单元格中都有期望的元素。

You need to, and can, fully control how your data source array holds data. In this case, it is arrayData - I also have a feeling that this is in some way related to myList, but it is not visible from your code snippet. Work on how elements are arranged within arrayData and then you will have expected elements in all cells.

这篇关于Swift:未按indexPaths的顺序调用cellForRowAtIndexPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆