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?

3
  • What you have in your self.array ? Are they string names of your imagesviews ? Commented May 5, 2013 at 11:03
  • 1
    You have forgotton the semi colons to end C statements and do you really want to loop just over the second line - I think you have forgottem the {} - Hint alwys use braces for all loops Commented May 5, 2013 at 11:04
  • Yes, it's a mutable array which has strings already in it Commented May 5, 2013 at 11:06

2 Answers 2

2

You are missing some basic C punctuation. You have forgotton the semi colons to end C statements and do you really want to loop just over the second line - I think you have forgotten the {} - Hint alwys use braces for all loops.

So Code would be like

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

Also [ are used for messages and should only appear on the right hand side of an assignement (=)

I would suggest you need to look at some C and Objective C tutorials to show correct code and describe the syntax.

Sign up to request clarification or add additional context in comments.

Comments

0

You forgot the semicolons and the third line is wrong:

Change your code to:

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

Using [] means we send a message to an object. We cannot use the = sign in a message.

1 Comment

@ the downvoter: Can you please explain what's wrong with my answer so that I can update it? Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.