我使用 Web 服务 API 从数据库(mySQL)加载信息。转换到 UITableViewController 时,我在 VieDidLoad 方法中检索包含类别的数组。但是,我无法显示进入表格视图单元格的类别数组。另一方面,当我初始化类别 NSMutubaleArray 并对其进行硬编码时,表格视图确实显示了信息。我试图了解在加载此数组并将其填充到 tableview 的步骤中我做错了什么。这是我的代码:
- (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];
}];
}
任何帮助将不胜感激。谢谢!
更新#1:
JSON 返回是一个带有 NSDictioanry 的数组。我打印出它的内容只是为了确保,通过调用 JsonArray objectForKey['categories'] 并得到这个:
SwiphtMVPClone[2410:11303] Array at Index 0 = Trending
SwiphtMVPClone[2410:11303] Array at Index 1 = Sports
SwiphtMVPClone[2410:11303] Array at Index 2 = Portraits
SwiphtMVPClone[2410:11303] Array at Index 3 = Art
现在,我的应用程序实际上正在崩溃 - 收到此错误:
[__NSCFDictionary isEqualToString:]: unrecognized selector sent to instance 0x72a85d0