【问题标题】:[__NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x16e09f70'[__NSCFString countByEnumeratingWithState:objects:count:]:无法识别的选择器发送到实例 0x16e09f70'
【发布时间】:2016-07-19 15:11:03
【问题描述】:

由于未捕获的异常 'NSInvalidArgumentException' 导致错误终止应用程序,原因:'-[__NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x16e09f70'

if (finalArray.count != 0)
    {
        NSMutableDictionary *fetchDict = [[NSMutableDictionary alloc]initWithDictionary:[finalArray objectAtIndex:indexPath.row]];
        NSMutableArray *valueArr = [[NSMutableArray alloc]initWithArray:[fetchDict allValues].mutableCopy];


        for (NSMutableArray *one in valueArr) {
            for (NSMutableArray *two in one) // Program Stops on This Line
            {
                cell.textLabel.text = [NSString stringWithFormat:@"%@",[two valueForKey:@"Note"]];
            }
        }

    }
}

【问题讨论】:

  • 所以你认为该数组包含数组,但事实并非如此,它至少包含一个字符串...

标签: ios objective-c nsarray


【解决方案1】:

试试这个

if (finalArray.count != 0)
    {
        NSDictinory *fetchDict = [finalArray objectAtIndex:indexPath.row];

  cell.textLabel.text = [NSString stringWithFormat:@"%@",[fetchDict valueForKey:@"Note"]];

    }
}

希望这会有所帮助。

【讨论】:

  • 感谢 Kamlesh 的努力。 Tim007 给出了可行的解决方案。
【解决方案2】:

试试这个

if (finalArray.count != 0)
{
    NSMutableDictionary *fetchDict = [[NSMutableDictionary alloc]initWithDictionary:[finalArray objectAtIndex:indexPath.row]];
    NSMutableArray *valueArr = [[NSMutableArray alloc]initWithArray:[fetchDict allValues].mutableCopy];


    for (NSMutableArray *one in valueArr) {
        if ([one isKindOfClass:[NSMutableArray class]]) { //Check if array here
            for (NSMutableArray *two in one) 
            {
                cell.textLabel.text = [NSString stringWithFormat:@"%@",[two valueForKey:@"Note"]];
            }
        }else {
            NSLog(@"Program stops because this one: %@", one);
        }
    }

}

【讨论】:

  • 工作谢谢!干杯!! (y)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-08
  • 1970-01-01
相关资源
最近更新 更多