Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用swift和parse进行TableView分页_Ios_Swift_Parse Platform_Pagination - Fatal编程技术网

Ios 使用swift和parse进行TableView分页

Ios 使用swift和parse进行TableView分页,ios,swift,parse-platform,pagination,Ios,Swift,Parse Platform,Pagination,我已经被一种方法搜索过,用swift和parse(parse.com)进行分页,但没有找到我想要的,所以我正在研究一个解决方案,并希望与大家分享。它已于2015年9月22日通过Xcode 7、iOS9和解析库1.8.2测试并投入使用: 在这种分页类型中,所有数据都存储在tableDataArray中,并且从不删除。当没有更多数据可下载时,变量tableDataArray将保持您的大小不变 首先在ViewController类上定义这些属性: @IBOutlet weak var myTableV

我已经被一种方法搜索过,用swift和parse(parse.com)进行分页,但没有找到我想要的,所以我正在研究一个解决方案,并希望与大家分享。它已于2015年9月22日通过Xcode 7、iOS9和解析库1.8.2测试并投入使用:

在这种分页类型中,所有数据都存储在
tableDataArray
中,并且从不删除。当没有更多数据可下载时,变量
tableDataArray
将保持您的大小不变

首先在
ViewController类上定义这些属性:

@IBOutlet weak var myTableView: UITableView!

var tableDataArray = [String]()

var countPage = 0    //number of current page

var stepPage = 50    //number of records by page

var maxRow = 0       //maximum limit records of your parse table class

var maxPage = 0      //maximum page

//Start the process to load the data
override func viewDidAppear(animated: Bool)
{
    self.tableDataArray.removeAll()

    getLimitRecordFromTable("parseClassName")
}
重写或声明
TableView协议的此函数

//Pagination
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath)
{
    let row = indexPath.row

    let lastRow = self.tableGamesArray.count - 1

    let pageLimit = (((self.countPage+1) * (self.stepPage)) - 1)  //prevision of the page limit based on step and countPage

    //Only for debug
    print("\(row) from [0,\(lastRow)] -> limit: \(pageLimit)")

    // 1) The last rown and is the last
    // 2) To avoid two calls in a short space from time, while the data is downloading
    // 3) The current array count is smaller than the maximum limit from database
    if (row == lastRow) && (row == pageLimit) && (self.tableGamesArray.count < self.maxRow)
    {
        self.countPage++

        print("Loading Page \(self.countPage) from \(self.maxPage)")

        self.loadGamesFromCloudDataStore(false)

        self.myTableView.reloadData()
    }
}
从解析数据云存储加载游戏:

func loadGamesFromCloudDataStore(parseClassName: String)
{
    let query = PFQuery(className: parseClassName)

    //Pagination
    query.limit = self.stepPage
    if( self.countPage > 0 )
    {
        query.skip = self.countPage * self.stepPage
    }

    query.findObjectsInBackgroundWithBlock(
    {
        (objects, error) -> Void in

        if let objects = objects
        {
            for object in objects
            {
                let id = object.objectId as String!

                self.tableDataArray.append(id)
            }
            self.myTableView.reloadData()
        }
    })
}

试过了,但没用,我得到了无限的加载你们都知道Parse中的PFQueryTableViewController内置了对分页和拉刷新的支持吗?这和设置每页对象的数量一样简单。尝试过但不起作用,我得到了无限的加载。你们都意识到Parse中的PFQueryTableViewController内置了对分页和拉刷新的支持吗?这与设置每页对象的数量一样简单。
func loadGamesFromCloudDataStore(parseClassName: String)
{
    let query = PFQuery(className: parseClassName)

    //Pagination
    query.limit = self.stepPage
    if( self.countPage > 0 )
    {
        query.skip = self.countPage * self.stepPage
    }

    query.findObjectsInBackgroundWithBlock(
    {
        (objects, error) -> Void in

        if let objects = objects
        {
            for object in objects
            {
                let id = object.objectId as String!

                self.tableDataArray.append(id)
            }
            self.myTableView.reloadData()
        }
    })
}