I try to use AFNetworking to get infos from server and set the database in UITableview
, please look following codes:
-(void)requestDB:(NSInteger)typeID {
NSString *picRequestURL = [NSString stringWithFormat:@"%@/infos/list/typeid/%ld",API_URL,(long)typeID];
NSURL *URL = [NSURL URLWithString:picRequestURL];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
op.responseSerializer = [AFJSONResponseSerializer serializer];
op.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
if ([[[responseObject objectForKey:@"status"] stringValue] isEqualToString:@"201"]){
[self setSquaretableData:[responseObject objectForKey:@"list"]];
if ([self.SquaretableData count] != 0) {
[self.tableview reloadData];
}
}
else {
}
}
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"Error: %@", error);
}];
[[NSOperationQueue mainQueue] addOperation:op];
}
in viewdidload
, I draw a uitableview, and also call [self requestDB:1]
, but when enter this viewcontroller, all infos in tableview will load so slowly, sometimes, it can't be showed, is my code wrong, is there a right way to do this, thanks.