I have a UITableView that loads content from a xml file inside a webserver.
- The TableView is inside a tab Bar Controller;
- I Call
[table reloadData]
inside theTBXMLSuccessBlock
; - The problem is that the content of the TableView dont update.
- I am using TBXML library;
After the Button have been clicked, How to says to tableVIew that XML file have been downloaded and show it?
- (IBAction)leftButton:(UIButton *)sender {
if (a<=2 && a != 0) {
a = a - 1;
NSString *leftURL = self.getDate;
[self loadURL:leftURL];
}
}
- (void)loadURL:(NSString *)newURL{
if (newURL == NULL) {
newURL = self.getDate;
}
// Create a success block to be called when the asyn request completes
TBXMLSuccessBlock successBlock = ^(TBXML *tbxmlDocument) {
NSLog(@"PROCESSING ASYNC CALLBACK");
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
// If TBXML found a root node, process element and iterate all children
if (tbxmlDocument.rootXMLElement)
{
// Obtain root element
TBXMLElement * root = tbxml.rootXMLElement;
if (root)
{
_storeArray = [NSMutableArray new];
TBXMLElement * elem_PLANT = [TBXML childElementNamed:@"news" parentElement:root];
while (elem_PLANT !=nil)
{
TBXMLElement * elem_title = [TBXML childElementNamed:@"title" parentElement:elem_PLANT];
NSString *titleName = [TBXML textForElement:elem_title];
TBXMLElement * elem_artist = [TBXML childElementNamed:@"text" parentElement:elem_PLANT];
NSString *artistName = [TBXML textForElement:elem_artist];
TBXMLElement * elem_thumb = [TBXML childElementNamed:@"thumb_url" parentElement:elem_PLANT];
NSString *thumbName = [TBXML textForElement:elem_thumb];
NSDictionary *dictionary = [[NSDictionary alloc]initWithObjects:@[titleName, artistName, thumbName] forKeys:@[@"title", @"text", @"thumb"]];
elem_PLANT = [TBXML nextSiblingNamed:@"news" searchFromElement:elem_PLANT];
[_storeArray addObject:dictionary];
}
}
[_tableView reloadData];
}
};
// Create a failure block that gets called if something goes wrong
TBXMLFailureBlock failureBlock = ^(TBXML *tbxmlDocument, NSError * error) {
NSLog(@"Error! %@ %@", [error localizedDescription], [error userInfo]);
};
// Initialize TBXML with the URL of an XML doc. TBXML asynchronously loads and parses the file.
tbxml = [[TBXML alloc] initWithURL:[NSURL URLWithString:newURL]
success:successBlock
failure:failureBlock];
}
EDIT: ReloadData inside buttonClick
- (IBAction)leftButton:(UIButton *)sender {
if (a<=2 && a != 0) {
a = a - 1;
NSString *leftURL = self.getDate;
[self loadURL:leftURL];
[_tableView reloadData];
}
}
- (IBAction)rightButton:(UIButton *)sender {
if (a<2) {
a = a + 1;
NSString *rightURL = self.getDate;
[self loadURL:rightURL];
[_tableView reloadData];
}
}
When app launch: - URL number 1 is loaded; - URL number 1 is showed; When I click one time right: - URL number 2 is loaded; - Nothing happen; When I click one more time right: - URL number 3 is loaded; - URL number 2 is showed; When I click one time left: - URL 2 is loaded; - URL 3 is showed; When I click one more time left: - URL 1 is loaded; - URL 2 is showed;