Я создал nsmutablearray, который содержит все записи, и, насколько это возможно, все работает нормально.
Проблема в том, что после успешного извлечения данных с сервера и сохранения их в массиве я пытаюсь обновить таблицу, чтобы показать данные, используя данные. Около 5 секунд, чтобы заполнить таблицу 20 рядов. Странная часть заключается в том, что выборочное производство происходит очень быстро, поэтому данные доступны сразу. Я не понимаю, что занимает так долго. Вот некоторая информация из журнала: < /p>
Код: Выделить всё
2012-03-17 18:46:01.045 MakeMyApp[4571:207] numberOfSectionsInTableView: 1
2012-03-17 18:46:01.047 MakeMyApp[4571:207] numberOfRowsInSection: 0
2012-03-17 18:46:01.244 MakeMyApp[4571:1f03] numberOfSectionsInTableView: 1
2012-03-17 18:46:01.245 MakeMyApp[4571:1f03] numberOfRowsInSection: 20
2012-03-17 18:46:01.245 MakeMyApp[4571:1f03] Ok, I'm done. 20 objects in the array.
2012-03-17 18:46:01.246 MakeMyApp[4571:1f03] Finished XML processing.
2012-03-17 18:46:06.197 MakeMyApp[4571:1f03] cellForRowAtIndexPath:
Код: Выделить всё
numberOfRowsInSection:Вы видите, что менее чем через секунду массив заполняется 20 объектами и всем рабочим процессом, выполненным XML. Как cellforroworatindexpath: запускается всего через 5 секунд?
Код: Выделить всё
- (void)createRequestFromXMLElement:(TBXMLElement *)element {
// Let's extract all the information of the request
int requestId = [[TBXML valueOfAttributeNamed:@"i" forElement:element] intValue];
TBXMLElement *descriptionElement = [TBXML childElementNamed:@"d" parentElement:element];
NSString *description = [TBXML textForElement:descriptionElement];
TBXMLElement *statusElement = [TBXML childElementNamed:@"s" parentElement:element];
int status = [[TBXML textForElement:statusElement] intValue];
TBXMLElement *votesCountElement = [TBXML childElementNamed:@"v" parentElement:element];
int votesCount = [[TBXML textForElement:votesCountElement] intValue];
// Creating the Request custom object
Request *request = [[Request alloc] init];
request.requestId = requestId;
request.description = description;
request.status = status;
request.votes_count = votesCount;
[requestsArray addObject:request];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
appListCell *cell = (appListCell *)[tableView dequeueReusableCellWithIdentifier:@"appListCell"];
Request *request = [requestsArray objectAtIndex:indexPath.row];
cell.appIdLabel.text = [NSString stringWithFormat:@"#%d", request.requestId];
cell.appTextLabel.text = request.description;
cell.appVotesLabel.text = [NSString stringWithFormat:@"%d votes", request.votes_count];
return cell;
}
- (void)traverseXMLAppRequests:(TBXMLElement *)element {
int requestCount = 0;
TBXMLElement *requestElement = element->firstChild;
// Do we have elements inside ?
if ((requestElement = (element->firstChild))) {
while (requestElement) {
[self createRequestFromXMLElement:requestElement];
requestCount++;
requestElement = [TBXML nextSiblingNamed:@"r" searchFromElement:requestElement];
}
}
[self.tableView reloadData];
NSLog(@"Ok, I'm done. %d objects in the array.", [requestsArray count]);
}
Подробнее здесь: https://stackoverflow.com/questions/975 ... -much-time
Мобильная версия