NSRangeException from removeObjectsInRange:但传递的范围在bounds内 [英] NSRangeException from removeObjectsInRange: but passed range is within bounds

查看:527
本文介绍了NSRangeException from removeObjectsInRange:但传递的范围在bounds内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误,这没有任何意义。


*由于未捕获异常终止应用程序'NSRangeException' ,原因:'* - [NSMutableArray removeObjectsInRange:]:range {11,15}扩展超出边界[0 .. 15]'


我在这里做错了什么?我在数组的界限内。删除数组中的最后一个对象是否会导致问题?

解决方案

NSRange 是长度,而不是端点。




$ b

$ b

  [myArray removeObjectsInRange:(NSRange){11,5}]; 


I am getting the error below, which makes no sense.

* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSMutableArray removeObjectsInRange:]: range {11, 15} extends beyond bounds [0 .. 15]'

What am I doing wrong here? I am within bounds of the array. Does removing the last object in the array cause issues?

解决方案

The second field of an NSRange is length, not endpoint. You are trying to remove fifteen objects, starting from index 11.

Instead, you want to do something along the lines of:

[myArray removeObjectsInRange:(NSRange){11, 5}];

这篇关于NSRangeException from removeObjectsInRange:但传递的范围在bounds内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆