これは実際には答えではありませんが、コメントするには長すぎます。あなたが投稿したコードに問題はありません。getMoreProblems のコードを新しいプロジェクトに貼り付け、結果を確認するために必要なデリゲート メソッドを追加しました。結果の文字列を見ると、(getMoreProblems への最初の呼び出しから) 受け取った最初のページで 1 から始まり、getMoreProblems への 2 回目の呼び出しで問題 51 から始まる問題番号が表示されます。getMoreProblems メソッドに追加したのは、最後の if-else 句だけです。ここに私が使用したコードがあります:
@synthesize window = _window,receivedData;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
problemsPage = 0;
[self getMoreProblems];
}
-(void)getMoreProblems {
problemsPage++;
NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"http://projecteuler.net/problems;page=%d",problemsPage]];
NSURLRequest *req=[NSURLRequest requestWithURL:url];
NSLog(@"%p",conn);
conn=[[NSURLConnection alloc] initWithRequest:req delegate:self];
NSLog(@"%p",conn);
if (conn) {
self.receivedData = [NSMutableData data];
} else {
NSLog(@"The Connection Failed");
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSLog(@"%@",response.URL);
[self.receivedData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSLog(@"In connection:didReceiveData:");
[self.receivedData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(@"Succeeded! Received %lu bytes of data",[receivedData length]);
NSString *page = [[NSString alloc] initWithData:self.receivedData encoding:NSUTF8StringEncoding];
NSLog(@"%@",page);
[self performSelector:@selector(getMoreProblems) withObject:nil afterDelay:5];
}
だから、私はあなたの問題を再現することはできません.あなたが投稿していないコードのどこかにあると思います.