3

カスタムの「ページパラメータ」で「RKPaginator」を使用するにはどうすればよいですか?私のAPIは「ページ」パラメータを提供しません。ページネーションに次のようなパターンを使用します。

" http://my.domain.com/api/lists/?limit=5&offset=10 "

「オフセット」は次のページのパラメータです。

私のAPIからのJSONリターンは次のようになります。

"meta": {
    "next": "/api/lists/?limit=5&offset=15",
    "total_count": 22,
    "previous": "/api/lists/?limit=5&offset=5",
    "limit": 5,
    "offset": 10
},

または、このようなリクエストを処理するためにtastypieをカスタマイズする方が簡単でしょうか?" http://my.domain.com/api/lists/?page=1 "どのメソッドをオーバーライドする必要がありますか?

どうもありがとう。

4

1 に答える 1

4

RKPaginator :: loadPageメソッドをobjective-cカテゴリでオーバーライドし、次のコード行に示すように、ページ番号と制限からのオフセットを計算します。

#import "RKPaginator+Tastypie.h"
#import <objc/runtime.h>

@implementation RKPaginator (Tastypie)

- (void)TastypieLoadPage:(NSUInteger)pageNumber
{
    [self TastypieLoadPage:(pageNumber-1) * self.perPage];
}

+ (void)load {
    method_exchangeImplementations(class_getInstanceMethod(self, @selector(loadPage:)), class_getInstanceMethod(self, @selector(TastypieLoadPage:)));
}

@end

そして、ここにRKPaginatorオブジェクトの構築があります。

RKPaginator *paginator = [[RKObjectManager sharedManager] paginatorWithPathPattern:@"yourResource/?limit=:perPage&offset=:currentPage"];
于 2013-02-09T16:40:39.367 に答える