2011-03-24 13 views
0

シンプルなコードはこちらです。NSURLConnectionオブジェクトは解放できません。

.h 
@interface testXML : UIViewController { 
    NSURLConnection *connect; 
} 
@property (nonatomic, retain) NSURLConnection *connect; 

.m 
@synthesize connect; 
- (void)viewDidLoad { 
    connect = [[NSURLConnection alloc] init]; 
    self.connect = [[NSURLConnection alloc] init]; 
    [super viewDidLoad]; 
} 

viewDidLoadが呼び出されると、EXC_BAD_ACCESS信号を受信します。

問題が何ですか?

ありがとうございます!

答えて

1

NSURLConnectionを使用する必要があります(文字列に希望のリンクがあると仮定します)。 開始後に接続を解放できます。複数回使用する場合は、connectionとiVarを作成し、以下のメソッドを呼び出します。

NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLwithString:string]]; 
    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]      
    [request release]; 
    [connection release]; 
+0

再生いただきありがとうございます。しかし問題は、オブジェクトを解放して新しいオブジェクトを指す必要があるときです。それはダウンするだろう。 – Jerry

+0

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {connection = nil; } - (void)connectionDidFinishLoading:(NSURLConnection *)接続{ 接続= nil; } – Shreesh

関連する問題