Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

loon3y

macrumors 65816
Original poster
Oct 21, 2011
1,235
126
i have a barcode scanning app, and i have an image view showing the picture of the recently scanned item, through a web service. it worked in the beginning, but after i changed something a while back it stopped showing up. now I'm trying to fix this problem. in only appears when i go out of the view controller (via tab bar) and go back in, here is my viewWillAppear code:







Code:
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    // use the product code for image, even if UPC is scanned
    NSString *sURL = [[NSString alloc] initWithString:[NSString stringWithFormat:@"http://******.*****.com:90/prodimage/%@.jpg", displayText.text]];
    NSData *mydata = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",sURL]]];
    UIImage *image = [[UIImage alloc] initWithData:mydata];
    [invenImage setImage:image];
}
 
Try telling the image view needsDisplay
Code:
[yourImageView setNeedsDisplay:YES];
 
Last edited by a moderator:
Try telling the image view needsDisplay
Code:
[yourImageView setNeedsDisplay:YES];




thanks but it didnt work, i running Xcode 4.3.1, so i don know if its the new version but there isn't a boolean after the code in my Xcode.





is there a method or function where i can refresh/reload the image that i can add at the end of viewWillAppear?
 
is there a method or function where i can refresh/reload the image that i can add at the end of viewWillAppear?

That's what setNeedsDisplay should do.
 
That's what setNeedsDisplay should do.



damn it, it worked before no problem, but after a co worker changed some coding in another view controller (using global variables) it stopped working.
 
Did you confirm that this is being called the first time the view is displayed by setting a breakpoint?

----------

Also, not related to your problem, but this line:

Code:
NSString *sURL = [[NSString alloc] initWithString:[NSString stringWithFormat:@"http://******.*****.com:90/prodimage/%@.jpg", displayText.text]];

could be changed to this:

Code:
NSString *sURL = [NSString stringWithFormat:@"http://******.*****.com:90/prodimage/%@.jpg", displayText.text];
 
cMacSW - I was reading this thread and was also wondering in the begining why he did not just use 'stringWithFormat'.

loon3y - When I develop problems like this I NSLog after every line of code to check to make sure my results are what I expected them to be.
 
The docs says there are situations where viewWillAppear will not be called, that's why setting a break point may help here.
 
Resolved:



basically i shouldn't of called the image in my barcode function or viewWillAppear or viewDidAppear.






i had to put it in my XML parse section of the code, because when I'm calling the image I'm using a store specified product code rather than calling it by the UPC when i scan. ( i know it should be either or but everything is mickey mouse and going to cleanup/optimize it later)






Code:
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 
{
    
    if ([elementName isEqualToString:@"itemno"])
    {
        displayText.text = capturedCharacters;
        
        // display the image on 1st viewcontroller
        NSString *sURL = [[NSString alloc] initWithString:[NSString stringWithFormat:@"http://*****.******.com:90/prodimage/%@.jpg", capturedCharacters]];
        NSData *mydata = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",sURL]]];
        UIImage *image = [[UIImage alloc] initWithData:mydata];
        [invenImage setImage:image];
        [invenImage setNeedsDisplay];
    }
 
    [capturedCharacters release];
    capturedCharacters = nil;
    
    if ([elementName isEqualToString:@"str_partinfo"]) {
        // We are no longer in an item element
        inItemElement = NO;
    }
}



hope this helps out anyone that gets confused using lineapro
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.