Como adicionar paginação no UITableView.? [fechadas]
Analiso dados da API para a primeira página e os adiciono aoUITableView
, agora as páginas podem ser múltiplas, digamos 100, também recebo o número total de páginas da API também. mas como vou implementá-lo no tableView para todas as páginas e mostrar o indicador durante a rolagem. Dê uma olhada no meu código
NSURL *theURL = [NSURL URLWithString:@"http://qa.networc.in:1336/api/dispatcher/rideScheduled/:1"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20.0f];
//Specify method of request(Get or Post)
[theRequest setHTTPMethod:@"GET"];
//Pass some default parameter(like content-type etc.)
[theRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[theRequest setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:token forHTTPHeaderField:@"x-access-token"];
NSURLResponse *theResponse = NULL;
NSError *theError = NULL;
NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&theResponse error:&theError];
if (responseData == nil)
{
return;
}
NSDictionary *dataDictionaryResponse = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&theError];
NSLog(@"url to send request= %@",theURL);
NSLog(@"%@",dataDictionaryResponse);
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:theRequest
completionHandler:
^(NSData *data, NSURLResponse *response, NSError *error) {
NSLog(@"Response:%@ %@\n", response, error);
if(error == nil)
{
NSString * text = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog(@"Data = %@",text);
}
dictionary = [[NSJSONSerialization JSONObjectWithData:data options:0 error:nil]objectForKey:@"data"];
NSArray *total = [dictionary objectForKey:@"total"];
NSLog(@"latlop %@", total);
NSArray *IDArray = [dictionary objectForKey:@"docs"];
for (NSDictionary *Dict in IDArray)
{
NSMutableDictionary *temp = [NSMutableDictionary new];
[temp setObject:[Dict objectForKey:@"_id"] forKey:@"_id"];
NSLog(@"temp %@", temp );
NSString *booknumber = [Dict objectForKey:@"bookingNumber"];
if([booknumber length] != 0)
[temp setObject:booknumber forKey:@"bookingNumber"];
NSMutableDictionary *stp1 = [Dict objectForKey:@"stop1"];
if ([[stp1 allKeys] containsObject:@"address"]) {
[temp setObject:[stp1 objectForKey:@"address"] forKey:@"address"];
];
}
NSMutableDictionary *stp2 = [Dict objectForKey:@"stop2"];
if ([[stp2 allKeys] containsObject:@"address"]) {
[temp setObject:[stp2 objectForKey:@"address"] forKey:@"address1"];
NSArray *latlongstp2 = [stp2 objectForKey:@"location"];
[temp setObject:[latlongstp2 objectAtIndex:0] forKey:@"latitude"];
[temp setObject:[latlongstp2 objectAtIndex:1] forKey:@"longitude"];
}
NSMutableDictionary *currentloc = [Dict objectForKey:@"currentLocation"];
if ([[currentloc allKeys] containsObject:@"address"]) {
[temp setObject:[currentloc objectForKey:@"address"] forKey:@"address1"];
}
[getid addObject:temp];
}
if (getid.count>0)
{
[self updateTable];
}
}];
[task resume];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1; //count of section
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [getid count];
}
- (void)tableView:(UITableView *)tableView willDisplayCell: (UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == [getid count] - 1 ) {
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ScheduleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell.BookingId.text = [[getid objectAtIndex:indexPath.row]objectForKey:@"_id"];
cell.BookingNo.text = [[getid objectAtIndex:indexPath.row]objectForKey:@"bookingNumber"];
cell.stop1.text = [[getid objectAtIndex:indexPath.row]objectForKey:@"address"];
cell.stop2.text = [[getid objectAtIndex:indexPath.row] objectForKey:@"address1"];
cell.Currentloc.text = [[getid objectAtIndex:indexPath.row] objectForKey:@"address"];
return cell;
}