Reputation: 397
I have a problem: when I call parser xml using TBXML in setCompletionBlockWithSuccess
of Afnetworking, my tableview is reloaded frequently and it can not stop.
...
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:afRequest];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success");
NSString * parsexmlinput = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSError * error = nil;
TBXML *sourceXML = [[TBXML alloc] initWithXMLString:parsexmlinput error:&error];
if (!error) {
/** get ROOT element **/
TBXMLElement *status = sourceXML.rootXMLElement;
NSString *statusString = [TBXML elementName:status];
NSLog(@"ROOT: %@", statusString);
/** get child element **/
TBXMLElement *listElement = [TBXML childElementNamed:@"FILE_LIST" parentElement:status];
TBXMLElement *itemElement = [TBXML childElementNamed:@"FILE" parentElement:listElement];
do
{
TBXMLElement *uploadIDElement = [TBXML childElementNamed:@"UPLOAD_ID" parentElement:itemElement];
[UploadIDArray addObject:[TBXML textForElement:uploadIDElement]];
TBXMLElement *filenameElement = [TBXML childElementNamed:@"FILENAME" parentElement:itemElement];
[FileNameArray addObject:[TBXML textForElement:filenameElement]];
} while ((itemElement = itemElement->nextSibling) != nil);
//fill in Dictionary
[Upload_Status_Dic setObject:FileNameArray forKey:@"FileName"];
[Upload_Status_Dic setObject:UploadIDArray forKey:@"UploadID"];
NSLog(@"Upload_Status_Dic %@",Upload_Status_Dic);
// release resources
NSLog(@"Dictionary is %@",Upload_Status_Dic);
//update your UI
AllItemsArray = [Upload_Status_Dic valueForKeyPath:@"FileName"];
NSLog(@"AllItemsArray is %@",AllItemsArray);
_tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
_tableView.dataSource = self;
_tableView.delegate=self;
_tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
[self.view addSubview:_tableView];
}
When run above code, my app always call numberOfRowsInSection
of UITableView. I think TBXML parser still yet parser XML done.How can I wait for TBXML parser done and the load data to UITableView? Any idea should be appreciate. Thanks in advance.
Upvotes: 0
Views: 257