简体   繁体   English

如何从数据库中获取数据时重新加载tableview?

[英]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 componentsSeparatedByString:@","];
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 . 我已经阅读了帖子,并尝试了很多不同的方法,但找不到正确的解决方案。所以这是我的问题:我有3个标签栏项目这一个是中间的。当我点击它显示tableview它有detailTextLabel .text。 I want to update the tableview when the user press the the tab bar i want him to see the updated one. 我想在用户按下标签栏时更新tableview,我希望他看到更新的标签栏。

Now i try several ways as you can see [self.tableView reloadData]; 现在我尝试了几种方法,你可以看到[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? 我把它放在UITableView类中的所有方法可以有人告诉我我在做什么错了吗?

in your .h file you have something like this: NSArray* myData 在你的.h文件中你有这样的东西: 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. 在.m文件中,tableView从此myData数组获取数据,您只需将新数据设置为tableView用作数据源的数组。

self.myData = res; right before you reload data 就在重新加载数据之前

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM