我正在使用swift 3並有一個TableView,我想在用戶在最後一行時觸發一段特定的代碼。出於某種原因,它完全忽略了這一點,並沒有引發關注。我甚至在那裏放置了一個斷點,並沒有打到它。這是我IOS TableView沒有響應最後一行代碼
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.row == self.Locations.count {
print("Last Row")
}
}
print語句沒有顯示也不是斷點。我的TableView代碼是這樣的
class HomePageC: UIViewController,UITableViewDataSource {
@IBOutlet weak var TableSource: UITableView!
var Locations = [String]()
override func viewDidLoad() {
super.viewDidLoad()
TableSource.allowsSelection = false
TableSource.dataSource = self
TableSource.estimatedRowHeight = 504
TableSource.showsVerticalScrollIndicator = false
TableSource.rowHeight = UITableViewAutomaticDimension
TableSource.tableFooterView = UIView()
}
func tableView(_ tableView:UITableView, numberOfRowsInSection section:Int) -> Int {
// This always returns 10 items
return Locations.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) ->
UITableViewCell {
// This just populates the fields as I have a custom TableView
}
非常感謝,正是我錯過的一切,現在一切正在進行。 –