伙计们,我在向数组添加nsurl和循环它们时遇到了一些问题。以下是我的代码的相关部分:
RSS阅读器AppDelegate.h:
@interface RSS_ReaderAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navigationController;
NSDictionary *RSSFeeds;
NSMutableArray *RSSFeedURLs;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) NSDictionary *RSSFeeds;
@property (nonatomic, retain) NSMutableArray *RSSFeedURLs;
RSS阅读器AppDelegate.m:
@implementation RSS_ReaderAppDelegate
@synthesize window;
@synthesize navigationController;
@synthesize RSSFeeds, RSSFeedURLs;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
NSURL *url1 = [[NSURL alloc] initWithString:@"http://<some url>"]; //real URL has been hidden
NSURL *url2 = [[NSURL alloc] initWithString:@"http://<some other url>"]; //real URL has been hidden
[RSSFeedURLs initWithObjects: url1, url2, nil];
[url1 release];
[url2 release];
for (NSURL *url in RSSFeedURLs) { //jumps right over this for loop
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
XMLParser *parser = [[XMLParser alloc] init];
[xmlParser setDelegate:parser];
//Start parsing the XML file.
BOOL success = [xmlParser parse];
if(success)
NSLog(@"No Errors");
else
NSLog(@"Error(s) encountered");
}//for
// Add the navigation controller's view to the window and display.
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
return YES;
}
所以
[RSSFeedURLs initWithObjects: url1, url2, nil];
当我运行调试器并键入“po rssfeedsurls”时,它似乎没有实际做任何事情,它报告:“无法访问地址为0x0的内存”,因此从未输入for循环。我不知道为什么会这样,有人能为我解释一下这种情况吗?事先谢谢。