How To Call An UIImage From Web?

Discussion in 'iOS Programming' started by loon3y, Nov 28, 2011.

  1. loon3y macrumors 65816


    Oct 21, 2011
    how can i call an UIImage from the web by scanning a barcode? I'm using linea pro.

    this is my coding

    - (void)viewDidLoad
        NSMutableString *sURL = [[NSMutableString alloc] initWithString:@"http://*********.com/prodimage/"];
        [sURL appendFormat:@"%@", lastBarcode];
        NSLog(@"sURL is: %@", sURL) ;
        UIImage * image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:sURL  ]]];
        UIImageView * imageView = [[UIImageView alloc]initWithImage:image];
        [self.view addSubview:imageView];
        [super viewDidLoad];
    	// Do any additional setup after loading the view, typically from a nib.

    when i scan the ns log doesn't run. so I'm assuming its not sending or getting data.
  2. jnoxx macrumors 65816


    Dec 29, 2010
    Aartselaar // Antwerp // Belgium
    Have u tried everything, also logging the frame etc, see if the pointers are set (not really looking through your code).
  3. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    If your NSLog is not showing up, I would think, based on your code snippet, that viewDidLoad is not getting called, since there doesn't seem to be anything to prevent the NSLog from getting executed once the method is started.
  4. chown33, Nov 28, 2011
    Last edited: Nov 28, 2011

    chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Please identify the class that contains your viewDidLoad method. Also identify its superclass.

    If your class isn't a UIViewController subclass, then viewDidLoad won't be called.

    If your class is a UIViewController subclass, but it's never loading a view, then viewDidLoad won't be called.

    Use of viewDidLoad isn't magic. You have to connect instances of your class into an active view hierarchy. If you don't make that connection, then nothing knows to call your viewDidLoad method.
  5. North Bronson macrumors 6502

    Oct 31, 2007
    San José
    This API will block your main thread. Do you see why that is? Do you see why that is not a good thing to do? Do you know how to load this without blocking the main thread?

Share This Page