标签: nsrangeexception

设置attributedText,NSRangeException错误

尝试通过选择设置我的UIText视图的属性文本属性.几乎是有效的.使用下面的红色字体颜色设置文本的操作.这有时会起作用,但通常会出错:

因未捕获的异常'NSRangeException'而终止应用程序,原因:'NSMutableRLEArray objectAtIndex:effectiveRange :: out of bounds'

即使文本视图中的字符似乎多于所选范围所指示的字符,也会发生这种情况.

- (IBAction)setText:(id)sender {

    NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithAttributedString:myTextView.attributedText];
    [string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(p1,p2)];

    myTextView.attributedText = string;

}
Run Code Online (Sandbox Code Playgroud)

p1和p2是所选文本的开头和结尾.它们是使用下面的代码生成的,它似乎按预期工作:

- (void)textViewDidChangeSelection:(UITextView *)textView {

    UITextRange *selectedRange = [myTextView selectedTextRange];

    p1 = [myTextView offsetFromPosition:myTextView.beginningOfDocument toPosition:[selectedRange start]];
    p2 = [myTextView offsetFromPosition:myTextView.beginningOfDocument toPosition:[selectedRange end]];

 }
Run Code Online (Sandbox Code Playgroud)

编辑:我在阅读@ borrrden的评论后解决了这个问题.而不是NSMakeRange(p1,p2)]我使用NSMakeRange(p1,p2-p1)].

uitextview nsattributedstring ios nsrange nsrangeexception

2
推荐指数
1
解决办法
1901
查看次数

范围超出范围4目标c

我有一个NSStringlength4按道理,这应该工作,并且expYear做,而是expMonth抛出一个越界异常?

expYear = [expDate substringWithRange:NSMakeRange(0, 2)];
expMonth = [expDate substringWithRange:NSMakeRange(2, 3)];
Run Code Online (Sandbox Code Playgroud)

substring objective-c nsstring ios nsrangeexception

2
推荐指数
1
解决办法
1352
查看次数

使用范围创建子数组时抛出 NSRangeException

这是我得到的一个非常奇怪的错误。是这样的:

'NSRangeException', reason: '*** -[NSArray subarrayWithRange:]: range {2, 3} extends beyond bounds [0 .. 3]'
Run Code Online (Sandbox Code Playgroud)

我不明白的是,范围 (2,3) 显然不会超出范围 (0,3)

事实上,它在这些范围内,因为我像这样设置了数组和范围:

NSRange range = NSMakeRange([wordArray indexOfObject:letterInWordArray]+1,wordArray.count-1);
NSMutableArray* sortedSubArray = [[NSMutableArray alloc] initWithArray:[wordArray subarrayWithRange:range]];
Run Code Online (Sandbox Code Playgroud)

本质上,我正在遍历一个名为 wordArray 的数组,并且我想创建一个包含我尚未遍历的所有项目的子数组。有人可以帮我从这里出去吗?

objective-c nsarray nsrange nsrangeexception

2
推荐指数
1
解决办法
1391
查看次数

NSMutableArray删除objectAtIndex NSRangeException IOS

NSRangeException尝试时遇到错误removeObjectAt:0.我不知道怎么可能.

-(void)removePoints:(ccTime *)tm
{

    NSLog(@"naughty %@",_naughtytoucharray);
    if ([_naughtytoucharray count]>0)
    {
        [_naughtytoucharray removeObjectAtIndex:0];
    }
}
Run Code Online (Sandbox Code Playgroud)

在日志上显示:

[4195:c07] naughty ( "{124, 98}", "{123, 98}", "{135, 97}", "{124, 98}", "{148, 94}", "{135, 97}", "{157, 93}", "{148, 94}", "{162, 92}", "{157, 93}", "{164, 92}", "{162, 92}" )

然后我收到以下错误: *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 11 beyond bounds [0 .. 10]'

当我设置断点时,我看到所有对象都是 0x0

在此输入图像描述

NSMutableArray被分配,初始化init和填写ccTouchesMoved

-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event  { …
Run Code Online (Sandbox Code Playgroud)

nsmutablearray cocos2d-iphone ios nsrangeexception

1
推荐指数
1
解决办法
477
查看次数

具有范围崩溃的子串

我有一个奇怪的问题.以下子字符串代码崩溃

NSString *string4 = @"<p>some</p><img></img><p></p>end of the story":
[string4 substringWithRange:NSMakeRange(7, [string4 length] - 1)];
Run Code Online (Sandbox Code Playgroud)

我假设范围在边界内但它仍然崩溃.知道为什么会这样吗?以下是它显示的错误.

*由于未捕获的异常'NSRangeException'终止应用程序,原因:' - [__ NSCFConstantString substringWithRange:]:范围或索引超出范围'*第一次抛出调用堆栈:(0x1c92012 0x10cfe7e 0x1c91deb 0x1c6aaa4 0x2bbc 0xf51c7 0xf5232 0x443d5 0x4476f 0x44905 0x4d917 0x27c5 0x11157 0x11747 0x1294b 0x23cb5 0x24beb 0x16698 0x1beddf9 0x1bedad0 0x1c07bf5 0x1c07962 0x1c38bb6 0x1c37f44 0x1c37e1b 0x1217a 0x13ffc 0x24fd 0x2425)libc ++ abi.dylib:terminate调用抛出异常(lldb)

substring objective-c nsrangeexception

1
推荐指数
1
解决办法
2886
查看次数

由于未捕获的异常“NSRangeException”而终止应用程序,原因:“*** -[__NSArray0 objectAtIndex:]:索引 2 超出空 NSArray 的范围

日志中的错误:

* 由于未捕获的异常“NSRangeException”而终止应用程序,原因:“* -[ NSArray0 objectAtIndex:]:索引 2 超出空 NSArray 的范围”*** 第一个抛出调用堆栈:( 0 CoreFoundation 0x000000010fdd8b0b __exceptionPreprocess + 171 1 libobjc.A. dylib 0x00000001143a6141 objc_exception_throw + 48 2 CoreFoundation 0x000000010fdf027d -[__NSArray0 objectAtIndex:] + 93 3 DropInn 0x000000010d598fc4 _TFC7DropInn21ListingViewController9tableViewfTCSo11UITableView 14didSelectRowAtV10Foundation9IndexPath_T_ + 5972 4 DropInn 0x000000010d599837 _TToFC7DropInn21ListingViewController9tableViewfTCSo11UITableView14didSelectRowAtV10Foundation9IndexPath_T_ + 87 5 UIKit 0x00000001122b3dcd -[UI TableView _selectRowAtIndexPath:动画:scrollPosition:notifyDelegate:] + 1763 6 UIKit 0x00000001122b3fe3 -[ UITableView _userSelectRowAtPendingSelectionIndexPath:] + 344 7 UIKit 0x00000001121697f3 _runAfterCACommitDeferredBlocks + 318 8 UIKit 0x00000001121567bc _cleanUpAfterCAFlushAndRunDeferredBlocks + 532 9 UIKit 0x000000011218828c _afterCACommitHandler + 137 10 CoreFoundation …

nsarray ios nsrangeexception swift

1
推荐指数
1
解决办法
8397
查看次数

[__NSArrayM objectAtIndex:]:索引2超出边界[0 .. 1]

我是一个新的iOS开发人员; 我有一个解析和动态单元格的应用程序,但当我运行应用程序时,我发现应用程序崩溃,因为标题上的原因我的代码如下

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{

    myArray = [[NSMutableArray alloc] init];


    //create new view if no view is available for recycling

   // view = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 250.0f, 300.0f)] autorelease];

    FXImageView *imageView = [[[FXImageView alloc] initWithFrame:CGRectMake(0, 0, 250.0f, 350.0f)] autorelease];
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    imageView.asynchronous = YES;
   // imageView.reflectionScale = 0.5f;
   // imageView.reflectionAlpha = 0.25f;
  //  imageView.reflectionGap = 10.0f;
    imageView.shadowOffset = CGSizeMake(0.0f, 2.0f);
    imageView.shadowBlur = 5.0f;
    imageView.cornerRadius = 10.0f;
    view = imageView;

    [ProgressHUD dismiss];

     NSString *string1 …
Run Code Online (Sandbox Code Playgroud)

nsarray ios nsrangeexception icarousel uicollectionview

0
推荐指数
1
解决办法
1万
查看次数