0

跳过以下

这些值是 TVC didSelectRowAtIndexPath 方法的前三行,当我连续选择一个项目时,它会给我各种异常。

我如何:

一种。检查以下字典、数组和 selectedCategory 是否具有值。

湾。如果事实证明他们不这样做,确保他们这样做吗?

NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];
NSArray *array = [dictionary objectForKey:@"News"];
NSString *selectedCategory = [array objectAtIndex:indexPath.row];

到这里 :

UIView tableView 的异常:numberOfRowsInSection:]:无法识别的选择器发送到实例 0x7193a60

4

3 回答 3

0

似乎 NSPlaceholderString 的 initWithString 方法得到了一个 nil 作为参数。所以,要弄清楚这究竟是什么时候发生的,最好添加一个异常断点。看看这里

于 2013-01-16T16:59:28.563 回答
0

要检查它们是否具有值,您可以检查...

[dictionary count];

[array count];

[selectedCategory length];

或者您可以检查...

dictionary == nil;

array == nil;

[selectedCategory isEqualToString:@""];

selectedCategory == nil;

有很多方法。不完全确定你在问什么,但你可以检查这些。

于 2013-01-16T17:01:11.647 回答
0

这是一个简单的调整。通常有比嵌套所有这些数据集合更好的方法来存储数据,但这是一个简单的替代方法,可以替代您已经拥有的应该阻止崩溃的方法。

// First check your listOfItems
NSDictionary *dictionary = NULL;
if (listOfItems.count > indexPath.section) {
    dictionary = [listOfItems objectAtIndex:indexPath.section];
}

// Next check your dictionary isn't null.
NSArray *array = NULL;
if (dictionary) {
    array = [dictionary objectForKey:@"News"];
}

// Next check your array and make sure your array has values.
NSString *selectedCategory = NULL;
if (array.count > indexPath.row) {
   selectedCategory = [array objectAtIndex:indexPath.row];
}

// Finally do your stuff
if (selectedCategory) {
    // Do your stuff
} else {
    // Something went wrong along the way and you don't have a selectedCategory string.
}
于 2013-01-16T17:02:29.030 回答