【问题标题】:UITableView indexPath.row not increasingUITableView indexPath.row 不增加
【发布时间】:2017-06-24 04:09:02
【问题描述】:

我正在将数据加载到 UITableView 中。

中的前 10 个单元格的第一次加载正确发生
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {}

indexPath.row 正确递增并将数据从数据源加载到正确的单元格中。然后,当到达表格底部时,我执行了更多负载。现在调用了 func tableView 但它卡在 indexPath.row = 9 处。我在

中实现了一个检查器
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

而且似乎添加了正确的行数。

编辑:我的第二个 uitableview 有问题(这个场景中有两个)检查器是一个打印语句,它被调用并返回正确的 uitableView,这发生在 tableView 卡在相同的值之前。

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

        if tableView == self.table {
            return users2.count

        }
        else {
            print("married barry", tableFeedCount)
            return tableFeedCount
        }
    }

【问题讨论】:

  • 您的“检查器”代码是什么样的?

标签: ios swift uitableview


【解决方案1】:

尝试以下操作:

声明布尔值

let boolNotMoreData : Bool = true

将新数据附加到您的数据源

 let arrResponse: [Any]? = (responseObject["news"] as? [Any])
 if arrResponse?.count == 0{
                boolNotMoreData = false;
        }
    for dictResponse in arrResponse as! [[String: Any]] {
          self.arrDataSource.append(NewsClass(responseDict: dictResponse))
        }
        self.tblViewNews?.reloadData()

现在获取新数据

private func tableView(_ tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        if indexPath.row == arrNews.count - 1 {
            if boolNotMoreData {
                currentPage += 1
                getYourData()
            }
        }
    }

【讨论】:

    【解决方案2】:

    这很成功

        @IBOutlet weak var Submitted: UITableView!
        @IBOutlet weak var ViewAssigenment: UITableView!
        var Arrayone:[String] = []
        var ArrayTwo:[String] = []
    
        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
            {
                var count:Int?
                if tableView == self.ViewAssigenment
                {
                    count = Arrayone.count
                }
                else if tableView == self.Submitted
                {
                    count = ArrayTwo.count
                }
                return count!
            }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
        {
    
            if tableView == self.ViewAssigenment
            {
                let cell = tableView.dequeueReusableCell(withIdentifier: "ViewCell") as!
                ViewAssigenmentTableViewCell
                let obj =Arrayone[indexPath.row]
    
               cell.lblTitle.text = obj.AssTitle
    
    
    
                return cell
    
            }
            else
            {
                let  cell1 = tableView.dequeueReusableCell(withIdentifier: "Submittcell") as! SubmittedAssigenmentTableViewCell
                let obj2 = ArrayTwo[indexPath.row]
    
                cell1.lbltitle.text = obj2.AssTitle
    
                return cell1
            }
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-09
      • 1970-01-01
      • 2011-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多