Reputation: 1184
I am parsing a Remote XML file and storing the values in an NSArray
. From the array I am using NSScanner
to get a particular image and allotting it to UIImageView
.
After scanning and getting the URL link of an image, I am assigning it to a UIImageView
but it's not showing the image. I am getting only a blank white window. The code is shown below:
MyViewController
NSURL *url = [NSURL URLWithString:@"http://myXML.com/Category.xml"];
AGSParser *parser = [[AGSParser alloc] init];
if ([parser loadXMLByURL:url]){
self.xmlProductsResults = parser.products;
NSArray *myArray = [_xmlProductsResults objectAtIndex:0];
NSString *string = [myArray description];
NSString *url = nil;
NSScanner *parser = [NSScanner scannerWithString:string];
[parser scanUpToString:@"imageUrlString" intoString:nil];
if (![parser isAtEnd]) {
[parser scanUpToString:@"=" intoString:nil];
NSCharacterSet *charset = [NSCharacterSet characterSetWithCharactersInString:@"\"'"];
[parser scanUpToCharactersFromSet:charset intoString:nil];
[parser scanCharactersFromSet:charset intoString:nil];
[parser scanUpToCharactersFromSet:charset intoString:&url];
NSLog(@"URL: %@",url);
}
}
When I check in NSLog
I am getting the string value as http://myimage.com/image1.png
. After this in my View Controller I am assigning this image url to UIImageView like this:
UIImageView *myImageView = [[UIImageView alloc] init];
myImageView.image = [UIImage imageNamed:url];
Here the image is not assigned. Can anyone suggest me how to solve this?
Upvotes: 1
Views: 1221
Reputation: 5745
Make [UIImage imageNamed:url]
into [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]]
.
For your other problem, look at V-Xtreme's answer
Upvotes: 6
Reputation: 7333
Application windows are expected to have a root view controller at the end of application launch
this happens when have not given the root view controller that is starting window in your app delegate class.
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
Upvotes: 3