小编Pau*_*ers的帖子

Objective C - NSArray和For循环结构

工作妨碍了学习目标C,但我现在又回到了它,这让我发疯了.

这是我的代码:

i=0;
    for (i=0;[photoList count]; i++) {
        NSLog(@"%i",i);
        NSLog(@"%@",[photoList objectAtIndex:i]);
        NSString *fileName = [photoList objectAtIndex:i];
        sendImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:nil]];
        UIImageWriteToSavedPhotosAlbum(sendImage,self,@selector(savedPhotoImage:didFinishSavingWithError:contextInfo:),NULL);}
Run Code Online (Sandbox Code Playgroud)

photoList只是一个NSArray,只有24个对象:

NSArray* photoList = [NSArray arrayWithObjects:@"Photo 1.jpg",
    @"Photo 2.jpg",
    @"Photo 3.jpg",
    @"Photo 4.jpg",nil];
Run Code Online (Sandbox Code Playgroud)

它有效...它将照片复制到相机胶卷......然后崩溃

2010-07-24 19:34:36.116 iCardz2go Poindexter [29662:207] *由于未捕获的异常'NSRangeException'终止应用程序,原因:'* - [NSArray objectAtIndex:]:索引24超出边界[0 .. 23]'

我尝试了各种配置,比如

for (i=0;1<23; i++)
Run Code Online (Sandbox Code Playgroud)

只能得到2010-07-24 19:51:01.017 iCardz2go Poindexter [29908:207]***由于未捕获的异常'NSInvalidArgumentException'终止app,原因:'+ [NSInvocation invocationWithMethodSignature:]:方法签名参数不能为nil'

所以它正在读取零并传递它.

我知道它会变得非常简单,我已经忘记了.为什么不跳出照片23(计数)的循环?

非常感谢您的帮助!P

iphone for-loop objective-c nsarray

5
推荐指数
2
解决办法
3万
查看次数

标签 统计

for-loop ×1

iphone ×1

nsarray ×1

objective-c ×1