这有什么不对?

时间:2012-03-28 20:05:22

标签: objective-c ios xcode plist

我有一个应用程序,其中我在plist中有一个URL,并且Web视图读取它以了解在开始时加载它的页面。这是代码:

.h

{
IBOutlet UIWebView *webView;
}
@property (retain, nonatomic) NSArray *array;
-(NSString *) dataFilePath;


.m

@synthesize array;
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *Array = [[NSMutableArray alloc] init];
[Array addObject:@"http://www.google.com"];
[Array writeToFile:[self dataFilePath] atomically:YES];
NSString *filePath = [self dataFilePath]; 
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{ 
    array = [[NSArray alloc] initWithContentsOfFile:filePath];
}
NSString *string = [NSString stringWithString:[array objectAtIndex:0]];
[webView loadRequest:[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:string]]];
}                   

-(NSString *) dataFilePath
{ 
    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentDirectory = [path objectAtIndex:0]; 

    return [documentDirectory stringByAppendingPathComponent:@"url.plist"];
}

问题是它不起作用..它给我一个sigabrt ......任何人都知道我做错了什么?

PS:我对plists不太了解。

1 个答案:

答案 0 :(得分:2)

您在loadRequest方法中有一些泄漏,请尝试将其更改为

[webView loadRequest:[[[NSURLRequest alloc] initWithURL:[NSURL urlWithString:string]] autorelease] ];