0

I'm trying to get the elements of an NSMutableArray, convert them to strings which are names of UIImageViews and change all the images to one image. I'm using this for loop:

for (int i = 0; i < [self.array count]; i++)
    NSString *currentelement = [self.array objectAtIndex:i]
    [UIImageView * theImageView = [self valueForKey:currentelement]
    [theImageView setImage:newimage];

but it gives me an error on the second line: Expected expression Any Ideas why?

4

2 回答 2

2

您缺少一些基本的 C 标点符号。您忘记了结束 C 语句的分号,并且您真的想在第二行上循环 - 我想您忘记了 {} - 提示总是对所有循环使用大括号。

所以代码就像

for (int i = 0; i < [self.array count]; i++)
{
    NSString *currentelement = [self.array objectAtIndex:i];
    UIImageView * theImageView = [self valueForKey:currentelement];
    [theImageView setImage:newimage];
}

此外 [ 用于消息,并且应该只出现在分配的右侧 ( =)

我建议您需要查看一些 C 和 Objective C 教程以显示正确的代码并描述语法。

于 2013-05-05T11:11:05.390 回答
0

您忘记了分号,第三行是错误的:

将您的代码更改为:

for (int i = 0; i < [self.array count]; i++) {
    NSString *currentelement = [self.array objectAtIndex:i];
    UIImageView *theImageView = [self valueForKey:currentelement];
    [theImageView setImage:newimage];
}

使用[]意味着我们向对象发送消息。我们不能=在消息中使用符号。

于 2013-05-05T11:01:42.683 回答