2013-07-12 72 views
-1

這是我的代碼,它給出了"Program received signal "SIGABRT".
我是新iOS發展。閱讀URL內容XCode sigabrt錯誤

- (IBAction)getData { 

    NSURL *URL = @"http://www.oeslabs.com/aa.txt"; 

    NSData *data = [NSData dataWithContentsOfURL:URL]; 

    NSString *string = [NSString stringWithUTF8String:[data bytes]];  
    if (string == nil) { 

     // an error occurred 
     label1.text [email protected]"Error"; 
    } 
    else{ 
     label1.text = string; 
    } 
} 

回答

2

你也可以把代碼

NSString *urlString = [NSString stringWithFormat:@"http://www.oeslabs.com/aa.txt"]; 
NSURL *myUrl = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 
. 
. 
. 
. 
. 

這裏是stringByAddingPercentEscapesUsingEncoding.的官方文檔用於轉換法律URL字符串。

+0

謝謝:)它確實工作 – albatross

+0

@albatross-我很高興幫助你,保持它:) – 2013-07-12 12:36:00

1

您試圖分配NSStringNSURL

更換

NSURL *URL = @"http://www.oeslabs.com/aa.txt"; 

隨着

NSURL *URL = [NSURL URLWithString:@"http://www.oeslabs.com/aa.txt"]; 
+0

@Desdenove - 很好趕:) :) – 2013-07-12 12:29:23

+0

謝謝它真的很有用,所以需要時間學習:) – albatross