Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 分析表视图中的数据时获取ObjectForkeydSubscript无法识别的选择器_Ios_Objective C_Json_Uitableview - Fatal编程技术网

Ios 分析表视图中的数据时获取ObjectForkeydSubscript无法识别的选择器

Ios 分析表视图中的数据时获取ObjectForkeydSubscript无法识别的选择器,ios,objective-c,json,uitableview,Ios,Objective C,Json,Uitableview,我正在将包含数据的json文件解析为具有不同自定义单元格的表视图。 在json文件中,我有不同类型的通道,如下所示: [ { text: "Text 1", channel: "Channel1" }, { text: "Text 2", channel: "Channel2" }, { text: "Text 3", channel: "Channel3" } ] 现在,当我尝试根据通道类型选择3个不同的自定义表视图单元格时,我得到了一个

我正在将包含数据的json文件解析为具有不同自定义单元格的表视图。 在json文件中,我有不同类型的通道,如下所示:

[
  {
  text: "Text 1", 
  channel: "Channel1"
  },
  {
  text: "Text 2", 
  channel: "Channel2"
  },
  {
  text: "Text 3", 
  channel: "Channel3"
  }
]
现在,当我尝试根据通道类型选择3个不同的自定义表视图单元格时,我得到了一个奇怪的错误。我是这样做的:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSDictionary *post = _posts[indexPath.row];

    if (post[@"channel"][@"Channel1"]) {
        Cell1 *cell = (Cell1*)[tableView dequeueReusableCellWithIdentifier:@"cell1" forIndexPath:indexPath];
        // Configuring the cell...
        return cell;
    } else if (post[@"channel"][@"Channel2"]) {
        Cell2 *cell = (Cell2*)[tableView dequeueReusableCellWithIdentifier:@"cell2" forIndexPath:indexPath];
        // Configuring the cell...
        return cell;
    } else if (post[@"channel"][@"Channel3"]) {
        Cell3 *cell = (Cell3*)[tableView dequeueReusableCellWithIdentifier:@"cell3" forIndexPath:indexPath];
        // Configuring the cell...
        return cell;
    } else {
    }
}
但当我在模拟器上运行它时,它会崩溃,并向我发出以下错误消息:

-[__NSCFString objectForKeyedSubscript:]: unrecognized selector sent to instance 0x7fa8bbf61540
2014-12-31 00:06:54.397 App[12767:2571748] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKeyedSubscript:]: unrecognized selector sent to instance 0x7fa8bbf61540'

我非常希望能找到解决方案或答案。

这一行不正确

if (post[@"channel"][@"Channel1"]) {
post[@channel]返回一个字符串,例如Channel1,因此不能在其上使用另一个下标[@Channel1]——这就是为什么会出现该错误

看起来你想做的是

if ([post[@"channel"] isEqualToString:@"Channel1"]) {

什么是_posts?您是如何解析JSON的?@MidhunMP u posts是我所说的JSON文件中保存文本的字典。我使用AFJSONRequestOperationYour行解析它,您想知道实际的通道看起来很奇怪。通常您会使用返回字符串的下标通道,并将其与不同的通道类型进行比较。谢谢!很好用!