我对 xml 解析器进行编码以读取 Internet 上的图像,但是当我在 xcode 上编译文件时遇到问题,他说:“线程 1:SIGABRT
这是代码:
查看 Controller.h :
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<NSXMLParserDelegate> {
IBOutlet UIImageView *imgView;
NSMutableArray *photos;
}
@end
视图控制器.m:
#import "ViewController.h"
@implementation ViewController
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (void)viewDidLoad
{
[super viewDidLoad];
photos = [[NSMutableArray alloc] init];
NSXMLParser *photoParser = [[[NSXMLParser alloc] initWithContentsOfURL: [NSURL URLWithString:@"http://davylebeaugoss.free.fr/Sans%20titre.xml"]] autorelease];
[photoParser setDelegate:self];
[photoParser parse];
NSURL *imageURL = [NSURL URLWithString:[photos objectAtIndex:0]];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData];
[imgView setImage:image];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ( [elementName isEqualToString:@"photo"])
{
[photos addObject:[attributeDict objectForKey:@"url"]];
}
}
@end
先感谢您!