0

我有一个问题:当我在setCompletionBlockWithSuccessAfnetworking 中使用 TBXML 调用解析器 xml 时,我的 tableview 经常重新加载并且无法停止。

...
    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];

}

当运行上面的代码时,我的应用程序总是调用numberOfRowsInSectionUITableView。我认为 TBXML 解析器仍然解析 XML 完成。如何等待 TBXML 解析器完成并将数据加载到 UITableView?任何想法都应该受到赞赏。提前致谢。

4

0 回答 0