iOS How To Call An UIImage From Web?

loon3y

macrumors 65816
Original poster
Oct 21, 2011
1,224
123
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.
 

dejo

Moderator
Staff member
Sep 2, 2004
15,981
450
The Centennial State
when i scan the ns log doesn't run. so I'm assuming its not sending or getting data.
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.
 

chown33

Moderator
Staff member
Aug 9, 2009
8,788
5,183
vertical
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.
 
Last edited:

North Bronson

macrumors 6502
Oct 31, 2007
395
1
San José
Code:
UIImage * image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:sURL  ]]];
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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.