0

我正在开发一个应用程序,在其中我从 URL 获取值,例如,将其作为 (demo.png),这里我正在做的是,我将字符串 <componentsSeparatedByString:@"." >array (Index 0 : demo & Index 1: png ). 而且,它工作正常。现在,我在这里受到打击,当 URL 中的值不包含时,".png, .jpeg"就会出现错误消息。我如何检查 ObjectAtIndex:1 中的值是否为空。我为此做的是,

编码:

if ([array45 objectAtIndex:1] == NSNULL NULL) {
   NSLog(@"object at index %i has no data", i);
}

错误信息:

[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'

帮助我提供有价值的解决方案。

4

2 回答 2

1
NSArray *aray = [@"demo.png" componentsSeparatedByString:@"."];

if ([[aray lastObject] isEqualToString:@"png"])
{
    NSLog(@"There is an image with .png");
}
else {
    NSLog(@"There is no image eith .png extension");
}
于 2012-09-01T09:16:04.593 回答
0

首先,您想找出数组中有多少对象。

int count = [array count];

如果您没有正确的计数,则不会检查索引中的内容。

于 2012-09-01T18:47:50.810 回答