안녕하세요, azure에서 2000 개 이상의 레코드를 다운로드해야합니다. 다운로드 할 수있는 최대 개수는 한 번에 1000 개이므로 완료 처리기를 사용하여 200 개를 다운로드해야합니다.
그들은이 코드를 예제로 게시했지만 사용 방법을 모르겠습니다.
이것을 Xcode에 복사하면 오류가 있습니다.
페이지에서 데이터 반환
모바일 서비스는 단일 응답으로 반환되는 레코드의 양을 제한합니다. 사용자에게 표시되는 레코드 수를 제어하려면 페이징 시스템을 구현해야합니다. 페이징은 MSQuery 개체의 다음 세 가지 속성을 사용하여 수행됩니다.
BOOL includeTotalCount
NSInteger fetchLimit
NSInteger fetchOffset
다음 예제에서 간단한 함수는 서버에서 20 개의 레코드를 요청한 다음 이전에로드 된 레코드의 로컬 컬렉션에 추가합니다.
- (bool) loadResults() {
MSQuery *query = [self.table query];
query.includeTotalCount = YES;
query.fetchLimit = 20;
query.fetchOffset = self.loadedItems.count;
[query readWithCompletion:(NSArray *items, NSInteger totalCount, NSError *error) {
if(!error) {
//add the items to our local copy
[self.loadedItems addObjectsFromArray:items];
//set a flag to keep track if there are any additional records we need to load
self.moreResults = (self.loadedItems.count < totalCount);
}
}];
}
당신의 도움을 주셔서 감사합니다.
그렇다면 Error " Expect Method Body "
코드에 잘못 복사하고 서식 문제가있는 것입니다.
단일 호출에서 페이징을 사용하여 데이터를로드하려면 다음과 같이합니다.
.h 파일에서 선언
typedef void (^CompletionBlock) ();
@property (nonatomic, strong) NSMutableArray *results;
.m 파일에서
- (void)loadData
{
self.results = [[NSMutableArray alloc] init];
MSClient *client = [MSClient clientWithApplicationURLString:@"YOUR_URL" applicationKey:@"YOUR_KEY"]
MSTable *table = [client tableWithName:@"YOUR_TABLE"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"YOUR_SELECT_FILTER"];
MSQuery *query = [[MSQuery alloc] initWithTable:table predicate:predicate];
//note the predicate is optional. If you want all rows skip the predicate
[self loadDataRecursiveForQuery:query withCompletion:^{
//do whatever you need to do once the data load is complete
}];
}
- (void)loadDataRecursiveForQuery:(MSQuery *)query withCompletion:(CompletionBlock)completion
{
query.includeTotalCount = YES;
query.fetchLimit = 1000; //note: you can adjust this to whatever amount is optimum
query.fetchOffset = self.results.count;
[query readWithCompletion:(NSArray *items, NSInteger totalCount, NSError *error) {
if(!error) {
//add the items to our local copy
[self.results addObjectsFromArray:items];
if (totalCount > [results count]) {
[self loadDataRecursiveForQuery:query withCompletion:completion];
} else {
completion();
}
}
}];
}
참고 :이 코드를 테스트하지는 않았지만 어느 정도 작동 할 것입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다