Mysql 从服务器加载TableView数据时出错
Im使用web服务API从数据库(mySQL)加载信息。当转换到UITableViewController时,我在VieDidLoad方法中检索包含类别的数组。但是,我无法显示进入表视图单元格的类别数组。另一方面,当我初始化类别NSMutubaleArray并对其进行硬编码时,tableview会显示信息。我试图理解在加载此数组并将其填充到tableview的步骤中我做错了什么。这是我的密码:Mysql 从服务器加载TableView数据时出错,mysql,ios,objective-c,uitableview,Mysql,Ios,Objective C,Uitableview,Im使用web服务API从数据库(mySQL)加载信息。当转换到UITableViewController时,我在VieDidLoad方法中检索包含类别的数组。但是,我无法显示进入表视图单元格的类别数组。另一方面,当我初始化类别NSMutubaleArray并对其进行硬编码时,tableview会显示信息。我试图理解在加载此数组并将其填充到tableview的步骤中我做错了什么。这是我的密码: - (void)viewDidLoad { [super viewDidLoad]; //When
- (void)viewDidLoad
{
[super viewDidLoad];
//When I init the _categoryList the way below, it displays the info.
//_categoryList = [[NSMutableArray alloc] initWithObjects:@"Trending",@"Sports",@"Portraits", @"Art",@"IdUser", nil];
_toCategory = [[NSString alloc]init];
//When I try to populate it from the server it doesnt work.
_categoryList = [[NSMutableArray alloc]init];
//just call the "getCategories" command from the web API
[[API sharedInstance] commandWithParams:[NSMutableDictionary dictionaryWithObjectsAndKeys:
@"getCategories",@"command",
nil]
onCompletion:^(NSDictionary *json) {
//got stream
NSArray *tempArray = [json objectForKey:@"result"];
for (int i=0;i<tempArray.count;i++){
[_categoryList insertObject:[tempArray objectAtIndex:i] atIndex:i];
}
//I verify that I was able to retrieve the array with the correct conent.
[self printArray:_categoryList];
NSLog(@"got categories");
[self.tableView reloadData];
}];
}
现在,我的应用程序实际上正在崩溃–出现以下错误:
[__NSCFDictionary isEqualToString:]: unrecognized selector sent to instance 0x72a85d0
好的,您的步骤是正确的:调用web服务以获取一些数据,当它完成时,将调用一个回调,您将尝试向_categoryList添加数据,然后刷新表视图。那么,首先,你有没有检查你得到的回应?名为json的字典的值是多少?您是否检查了主线程中是否调用了完成回调?这里有
reloadData
,它需要在主线程中。如果你无法在主线程中调用它,它可能会工作,也可能不工作,甚至可能会使你的应用程序崩溃。谢谢你的快速响应。我在帖子中添加了更多的信息@如何将重新加载的数据放在主线程中?您应该使用[self-printArray:_categoryList]的内容进行更新代码>,或在您调用的代码中搜索IsequalString:
,以及它与此代码的关系。您可能正确地重新加载了表,但在表委托中的某个地方,您正在从JSON对其中一个NSDictionary
调用IsequalString:
。我解决了这个问题!这是因为我没有将字典值赋给数组,而只是将字典本身赋给数组,这导致了问题。非常感谢你!我怎么投票给你?!
[__NSCFDictionary isEqualToString:]: unrecognized selector sent to instance 0x72a85d0