How to reload tableview when getting data from database?
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSString *country=[[NSUserDefaults standardUserDefaults]objectForKey:@"namecountry"];
//url's
NSURL *url = [NSURL URLWithString:@"someurl"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:country forKey:@"c_name"];
[request setRequestMethod:@"POST"];
[request setValidatesSecureCertificate:NO];
[request setDelegate:self];
[request startSynchronous];
NSString *response = [request responseString];
NSLog(@"%@",response);
res=[response componentsSepar开发者_C百科atedByString:@","];
NSLog(@"%@",[res objectAtIndex:18]);
show=[NSString stringWithFormat:@"%@",[res objectAtIndex:18]];
float f=[show floatValue];
show=[NSString stringWithFormat:@"%.2f %%",f];
[self.tableView reloadData];
}
I've read posts and try lots of different ways but can't find the correct solution.So here is my problem: I have 3 tab bar items this one is the middle one.When i click it shows the tableview and it has detailTextLabel.text . I want to update the tableview when the user press the the tab bar i want him to see the updated one.
Now i try several ways as you can see [self.tableView reloadData]; i put it all the methods in the UITableView class can anybody tell me what is wrong i am doing in this?
in your .h file you have something like this: NSArray* myData
in the .m file the tableView gets data from this myData
array
all you have to do is set the new data to the array your tableView uses as a datasource.
self.myData = res;
right before you reload data
精彩评论