gpt4 book ai didi

objective-c - 当使用cell.textLabel.text等于在线plist中的键时,应用程序崩溃

转载 作者:行者123 更新时间:2023-12-03 16:55:18 25 4
gpt4 key购买 nike

我知道以前曾发布过这样的问题,但是我试图获得直接针对我的代码的答案。我看过另一篇文章,并按照它进行到了这个阶段。

我的日志中有(null) libc++abi.dylib: terminate called throwing an exception行。我已经将其追溯到以下代码行:

normalCell.textLabel.text = [[displayArray objectAtIndex:indexPath.row] objectForKey:@"name"];

这是在我的 cellForRowAtIndexPath方法中,该方法具有以下代码:
static NSString *normalCellIdentifier = @"normalCell";
static NSString *topRowCellIdentifier = @"topRowCell";

UITableViewCell *normalCell = [tableView dequeueReusableCellWithIdentifier:normalCellIdentifier];
if (normalCell == nil)
{
normalCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:normalCellIdentifier];
}

UITableViewCell *topRowCell = [tableView dequeueReusableCellWithIdentifier:topRowCellIdentifier];
if (topRowCell == nil)
{
topRowCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:topRowCellIdentifier];
}

// Configure the cell...
if (searchBar.selectedScopeButtonIndex != 0)
{
normalCell.textLabel.text = [[displayArray objectAtIndex:indexPath.row] objectForKey:@"name"];
}

if (segmentedControl.selectedSegmentIndex == 0)
{
if (indexPath.section == 0)
{
[self makeButtonsForTableView:tableView atIndexPath:indexPath withTableViewCell:topRowCell];

[topRowCell addSubview:button1];
[topRowCell addSubview:button2];

topRowCell.selectionStyle = UITableViewCellSelectionStyleNone;
return topRowCell;
}
else
{
return normalCell;
}
}
else
{
return normalCell;
}
makeButtonsForTableView包含了按钮的所有代码,但这不是问题,因为我已从代码中删除了该代码,但问题仍然存在,因此无需添加该代码。
displayArray的内容取决于 selectedSegmentIndex上的 UISegmentedControlUISearchBar的选定范围而有所不同。

每个数组都从我的网站域导入获取其值,这些数组是:
modsArray
itemsArray
serversArray
pluginsArray
newItemsArray
newBlocksArray
newMobsArray

谢谢你提供的所有帮助。

-编辑22:40GMT-27/09/2012-

所以我在应用加载时记录了 displayArray的内容,这就是日志
2012-09-27 22:39:56.539 AppName[22949:11303] (
)
2012-09-27 22:39:56.675 AppName[22949:11303] (
)

-编辑23:13GMT-2012年9月27日-

有趣的是,当我更改选项卡并返回日志时,更改如下:
2012-09-27 23:13:14.074 MinePedia[23853:11303] DisplayArray Count: 0
2012-09-27 23:13:14.074 MinePedia[23853:11303] IndexPath Row: 0
2012-09-27 23:13:14.355 MinePedia[23853:11303] DisplayArray Count: 0
2012-09-27 23:13:14.355 MinePedia[23853:11303] IndexPath Row: 1

对此
2012-09-27 23:13:14.074 MinePedia[23853:11303] DisplayArray Count: 1
2012-09-27 23:13:14.074 MinePedia[23853:11303] IndexPath Row: 1
2012-09-27 23:13:14.355 MinePedia[23853:11303] DisplayArray Count: 1
2012-09-27 23:13:14.355 MinePedia[23853:11303] IndexPath Row: 0

有人知道这是什么意思吗?

-编辑23:42-27/09/2012-

好的,与以前不同的是,它现在不会崩溃,因此可以解决,谢谢Mayur,但是现在启动时,直到顶部的选项卡被更改,作用域和表 View 的索引路径仍大于计数。我该如何解决?

最佳答案

保持如下:

normalCell.textLabel.text = [NSString stringWithFormat:@"%@",[[displayArray objectAtIndex:indexPath.row] objectForKey:@"name"]];

这样,即使出现null值,也不会崩溃。

此外,请始终检查数组是否已填充,然后才像这样访问列表。
if (searchBar.selectedScopeButtonIndex != 0)
{
if(indexPath.row < [displayArray count])
{
normalCell.textLabel.text = [NSString stringWithFormat:@"%@",[[displayArray objectAtIndex:indexPath.row] objectForKey:@"name"]];
}
}

关于objective-c - 当使用cell.textLabel.text等于在线plist中的键时,应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12630130/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com