2017-06-24 36 views
0

我正在將數據加載到UITableView中。第一負載發生正確的第10個細胞中UITableView indexPath.row不會增加

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

的indexPath.row增量正確和數據加載到從所述數據源中的適當單元中。當到達桌子底部時,我再執行一次加載。現在FUNC的tableView被調用但它在

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

停留在indexPath.row = 9,我實現了一個檢查,它似乎已被添加行適當數量。

編輯:我有我的第二個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 
     } 
    } 
+0

請問你的 '檢查' 的代碼看起來像工作? – tek3

回答

0

嘗試以下操作:

聲明布爾

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() 
      } 
     } 
    } 
0

這成功地

@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 
     } 

    }