- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用下面的代码来检查一个对象是否存在,如果它存在则删除它:
if(titlescopy.count >= i)
{
if([[titlescopy objectAtIndex:i] isKindOfClass:[NSString class]])
{
[titlescopy removeObjectAtIndex:i];
}
}
但是,我收到了这个错误:
* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]' * First throw call stack: (0x365a56c3 0x3881e97f 0x364f1055 0x494b 0x37fdb8d5 0x37fe7d75 0x37fe7a81 0x38001ddd 0x38001b97 0x172bd 0x3805f8e5 0x3805f897 0x3805f875 0x3805f12b 0x3805f621 0x37f87d29 0x37f74f29 0x37f74843 0x34ea25d3 0x34ea2203 0x3657a593 0x3657a537 0x365793b9 0x364ec39d 0x364ec229 0x34ea131b 0x37fc88f9 0x283b 0x2798) libc++abi.dylib: terminate called throwing an exception (lldb)
为什么会这样?我使用的代码应该在尝试删除对象之前检查该对象是否存在,但显然不存在。
谢谢!
最佳答案
Objective-C 中的数组索引从 0 开始,因此 i = titlescopy.count 超出范围。将您的 if 语句更改为:
if(titlescopy.count > i)
关于iphone - NSArray removeObjectAtIndex 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12331542/
这是我在 ViewController.m 文件中的代码, - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animat
从我的 NSMutableArray 中删除时出现以下错误 -[__NSArrayI removeObjectAtIndex:]: unrecognized selector sent to inst
这是我不断收到的错误: 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSArrayI removeObjectAtIndex:]:无法识别的
我有一个 NSMutableArray,我分配给它: NSMutableArray *newElements = [[NSMutableArray alloc] initWithObjects:sel
我有一个 TableView ,其中包含许多我希望能够删除的行。填充 TableView 的数据存储在 NSMutableArray 中。要删除一行中的数据,我调用: - (void)deleteFr
我正在使用下面的代码来检查一个对象是否存在,如果它存在则删除它: if(titlescopy.count >= i) { if([[titlescopy objectAtIndex:i] isK
如果我有一个包含 10 个对象的 NSMutableArray 我运行这行代码 [tempArray removeObjectAtIndex:0]; 然后 [tempArray count] 应该返回
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
我有一个 UITableViewController,标题中有一个 NSMutableArray,如下所示: NSMutableArray *someArray; 我还声明了该属性: @propert
我正在尝试根据字符串的长度过滤掉一个字符串数组。总的来说,我对 Objective C 和 OOP 完全陌生。 wordList=[[stringFile componentsSeparatedByC
我正在尝试根据字符串的长度过滤掉一个字符串数组。总的来说,我对 Objective C 和 OOP 完全陌生。 wordList=[[stringFile componentsSeparatedByC
我有一个带有表格 View 的 View Controller ,您可以在其中删除单元格。我有另一个处理称为书签的类,该类称为 BookmarkHandler .有一些方法可以上传书签、获取整个书签数
我正在 SpriteKit 中进行测试和原型(prototype)制作,并拥有双击翻转的 Sprite 。我在 _theArray 中有 52 个 sprite,它包含当前在 View 中的 spri
我有一组用户,我试图将其转换为 NSMutableArray 以便能够使用 removeObjectAtIndex,但它不起作用。 我收到错误 Cast from '[ModelUser]?'如果我尝
在使用 NSMutableArray 时,我可以 addObject: 然后使用 removeObjectAtIndex:0 删除前面的对象。来自文档: To fill the gap, all el
我看过很多帖子,其中介绍了从数组中正确删除对象的各种方法,但我不确定哪种方法最适合我的实例。我正在从一个 plist 中加载一个字典,这个字典包含许多数组,这些数组包含另一个字典。所以我有 3 个存储
NSMutableArray 中的奇怪行为。 我已经创建了对象并填充了它。 NSMutableArray *array = [[NSMutableArray alloc]
我有一个简单的方法,可以将数组的第一个元素放在末尾,然后将所有元素向下移动一个索引: -(NSArray*)backUpNotes:(NSArray*)notes { NSMutableArr
我正在编写一个应用程序来显示来自门户的一些新闻。使用 JSON 文件从 Internet 获取新闻,然后使用 CoreData 模型将其存储到 NSMutableArray 中。显然,用户无法从 In
你好我是 ios 开发人员的新手。我想删除 tableview 中的行。我将实现代码但是当我滑动 tableview 时点击删除按钮而不是显示错误 [__NSCFArray removeObjectA
我是一名优秀的程序员,十分优秀!