내 응용 프로그램이 느린 이유를 알고 싶습니다. 여기 내보기 컨트롤러가하고있는 작업은 다음과 같습니다느린 iOS 응용 프로그램
는- (있는 viewDidLoad는) AFNetworking와 웹 서비스에서 데이터를 검색합니다.
- 응답을 구문 분석하고 사용자 지정 개체를 만들어 사전에 저장합니다.
- 테이블 뷰 데이터를 다시로드하여 사용자 지정 개체로 채 웁니다.
내 AFNetworking 전화 :
NSString *url = [Utils urlForObjectType:objectGames]; AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; AFJSONRequestSerializer *requestSerializer = [AFJSONRequestSerializer serializer]; [requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"]; manager.requestSerializer = requestSerializer; [manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { [self didReceiveGames:operation.responseData]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }];
의 TableView 방법 : 는이 AFNetworking 함께 할 수 없다, 난 그냥에서 응답을 저장 : 편집
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
NSString *competition = [competitionNames objectAtIndex:indexPath.section];
NSArray *competitionGames = [competitions objectForKey:competition];
Game *game = [competitionGames objectAtIndex:indexPath.row];
Team *teamA = [game teamA];
Team *teamB = [game teamB];
UILabel *labelTeamA = (UILabel *)[cell viewWithTag:100];
UILabel *labelTeamB = (UILabel *)[cell viewWithTag:101];
UILabel *labelResultA = (UILabel *)[cell viewWithTag:102];
[labelResultA setText:nil];
UILabel *labelResultB = (UILabel *)[cell viewWithTag:103];
[labelResultB setText:nil];
UIImageView *imageTeamA = (UIImageView *)[cell viewWithTag:104];
UIImageView *imageTeamB = (UIImageView *)[cell viewWithTag:105];
UILabel *labelState = (UILabel *)[cell viewWithTag:106];
[labelState setText:nil];
GameState state = [game state];
NSString *urlImageA = [Utils urlForObjectType:objectTeamImage andID:[teamA teamID]];
NSString *urlImageB = [Utils urlForObjectType:objectTeamImage andID:[teamB teamID]];
/* Time Background */
UIImageView *timeBackground = (UIImageView *) [cell viewWithTag:107];
[timeBackground setHidden:NO];
[cell setBackgroundColor:[UIColor clearColor]];
switch (state) {
case statePlayed: {
[labelResultA setText:[NSString stringWithFormat:@"%d", [game finalResultA]]];
[labelResultB setText:[NSString stringWithFormat:@"%d", [game finalResultB]]];
[timeBackground setHidden:YES];
}
break;
case stateFixture: {
/* Set labelState to hours */
NSDate *date = [game date];
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute fromDate:date];
NSString *minutes;
if ([components minute] == 0) {
minutes = @"00";
} else {
minutes = [NSString stringWithFormat:@"%d", [components minute]];
}
[labelState setText:[NSString stringWithFormat:@"%dh%@", [components hour], minutes]];
}
break;
case stateCancelled:
[labelState setText:@"CANCELLED"];
break;
case statePlaying: {
[labelResultA setText:[NSString stringWithFormat:@"%d", [game finalResultA]]];
[labelResultB setText:[NSString stringWithFormat:@"%d", [game finalResultB]]];
[timeBackground setHidden:YES];
}
break;
case statePostponed:
[labelState setText:@"POSTPONED"];
break;
case stateSuspended:
[labelState setText:@"SUSPENSED"];
break;
default:
break;
}
[labelTeamA setText:[teamA name]];
[labelTeamB setText:[teamB name]];
[imageTeamA setImageWithURL:[NSURL URLWithString:urlImageA]];
[imageTeamB setImageWithURL:[NSURL URLWithString:urlImageB]];
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSArray *competitionGames = [competitions objectForKey:[competitionNames objectAtIndex:section]];
return [competitionGames count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [competitionNames count];
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *header = [[NSBundle mainBundle] loadNibNamed:@"GamesHeaderIPAD" owner:self options:nil][0];
NSString *competitionName = [[competitionNames objectAtIndex:section] uppercaseString];
UILabel *labelCompetition = (UILabel *)[header viewWithTag:100];
[labelCompetition setText:competitionName];
return header;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 42;
}
NSUserDefaults, 거기에서 읽으면 여전히 느립니다.
감사합니다.
메인 스레드에서 "AFNetworking을 사용하여 웹 서비스에서 데이터 검색"? –
예. 백그라운드에서 실행하려면 어떻게해야합니까? –
"천천히"란 무엇을 의미합니까? viewDidLoad 함수에 문제가 있습니까? 또는 귀하의 UI가 즉시 열리지 만 나중에 데이터가 나타 납니까? –