How To Call An UIImage From Web?

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

  1. loon3y macrumors 65816

    loon3y

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

    this is my coding

    Code:
    - (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

    jnoxx

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

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    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

    Joined:
    Aug 9, 2009
    #4
    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

    Joined:
    Oct 31, 2007
    Location:
    San José
    #5
    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