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
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.
 
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.
 
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:
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.