Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed to see which UIImageView is empty and place an image there
    primarykey
    data
    text
    <p>Here's my problem. I have 3 UIImageViews that are empty by default, placed on a UIView that are is hidden at first.</p> <p>And they are supposed to be filled one after another when a user selects something. I know it sounds confusing, but I think my code below will clear things out: </p> <pre><code>- (IBAction)selectButtonPressed:(id)sender { if ([labelText.text isEqualToString:@"some text"]) { NSString *filePath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"someImage"] ofType:@"png"]; UIImage * image = (UIImage * )[UIImage imageWithContentsOfFile:filePath]; if (firstImage.image == nil) { firstImage.image = image; imagesView.hidden = YES; firstImage.hidden = NO; } // places it in the first Image View if it's empty ... else if (secondImage.image == nil) { secondImage.image = image; imagesView.hidden = YES; secondImage.hidden = NO; } // ... or in the second one if empty else { thirdImage.image = image; imagesView.hidden = YES; thirdImage.hidden = NO; // ... else in the third one } [filePath release]; [image release]; } // then does the same thing depending on the users selection. else if ([labelText.text isEqualToString:@"some other text"]) { NSString *filePath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"someOtherImage"] ofType:@"png"]; UIImage * image = (UIImage * )[UIImage imageWithContentsOfFile:filePath]; if (firstImage.image == nil) { firstImage.image = image; imagesView.hidden = YES; firstImage.hidden = NO; } else if (secondImage.image == nil) { secondImage.image = image; imagesView.hidden = YES; secondImage.hidden = NO; } else { thirdImage.image = image; imagesView.hidden = YES; thirdImage.hidden = NO; } [filePath release]; [image release]; } // and same thing below if none of the above. else { NSString *filePath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"yet another text"] ofType:@"png"]; UIImage * image = (UIImage * )[UIImage imageWithContentsOfFile:filePath]; if (firstImage.image == nil) { firstImage.image = image; imagesView.hidden = YES; firstImage.hidden = NO; } else if (secondImage.image == nil) { secondImage.image = image; imagesView.hidden = YES; secondImage.hidden = NO; } else { thirdImage.image = image; imagesView.hidden = YES; thirdImage.hidden = NO; } [filePath release]; [image release]; } // Code for checking which Image View is empty and place the image there. } </code></pre> <p>So, it launches and works fine, when I do the first selection. But for the 2nd one it says EXC_BAD_ACCESS and crashes. Sometimes it works for the first 2 selections and for the third one it crashes. </p> <p>Please let me know if it's confusing, I'll try to explain my intent as clear as I can. </p> <p>Thanks a lot</p> <p>UPDATE: Well, I think it's true that an answer appears when you ask the right question.</p> <p>Everything worked well, after I've used firstImage.image = [UIImage imageNamed:@"someImage"]; instead of the whole NSBundle method. Code became cleaner and works like a charm.</p> <p>However I'm not sure if there are any downsides to this. So if you guys can warn me of anything, I'm all opened to that. </p> <p>Thanks again.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload