无法从服务器加载TableView的数据

时间:2013-07-21 18:56:16

标签: mysql ios objective-c uitableview

我正在使用Web服务API从数据库(mySQL)加载信息。转换到UITableViewController时,我检索一个包含VieDidLoad方法中的类别的数组。但是,我无法显示表格单元格中的类别数组。当我初始化类别NSMutubaleArray并在另一方面硬编码时,tableview会显示信息。我试图了解在加载此数组并将其填充到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

0 个答案:

没有答案