I searched around for pagination but everything seems to point to pulling data from a server:
In my situation my data arrays are filled with static items wherein as I already know the count of what's inside of each array. My tabBar has three tabs and each tab has a tableVIew with different amounts of data
tableDataForTabOne = [DataModel]() // the array has 1000 items in it
tableDataForTabTwo = [DataModel]() // the array has 690 items in it
tableDataForTabThree = [DataModel]() // the array has 7 items in it
How do I paginate the arrays for the tableView into different pages? For example the first 10 items is 1 page, the next 10 items is another page, etc etc?
The question has nothing to do with the tabs. I don't know how to paginate on a tableView without pulling data from a server.
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak fileprivate var tableView: UITableView!
let tableDataForTabTwo = [DataModel]() //has 690 items in it
var pageNumber = 0
override func viewDidLoad() {
super.viewDidLoad()
...
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tableDataForTabTwo.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath) as! MyCell
cell.titleLabel.text = tableDataForTabTwo[indexPath.row]."some static title"
cell.imageView.image = tableDataForTabTwo[indexPath.row].UIImage(named: "some static image")
return cell
}
}