Ваша проблема в том, что блокируйте основной поток, используя sendSynchronousRequest. Пока данные загружаются, ваш поток блокируется, и поэтому ваша анимация тоже, и после того, как запрос был выполнен, анимация продолжается.
Мне нужно использовать connectionWithRequest: delegate: или initWithRequest: delegate: методы и установить делегат на себя. Вы можете найти более подробную информацию здесь: Using NSURLConnection
EDIT:
Пример:
В интерфейсе определить его:
@interface YourInterface {
@private
NSMutableData *receivedData;
}
затем в контроллере в viewDidLoad :
// your previous definition of your NSMutableRequest
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (theConnection) {
// Create the NSMutableData that will hold
// the received data
// receivedData is declared as a method instance elsewhere
receivedData=[[NSMutableData data] retain];
} else {
// inform the user that the download could not be made
}
закончить, снова в вас контроллер, реализовать эти методы:
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
// append the new data to the receivedData
// receivedData is declared as a method instance elsewhere
[receivedData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
// release the connection, and the data object
[connection release];
// receivedData is declared as a method instance elsewhere
[receivedData release];
// inform the user
NSLog(@"Connection failed! Error - %@ %@",
[error localizedDescription],
[[error userInfo] objectForKey:NSErrorFailingURLStringKey]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
// do something with the data
// receivedData is declared as a method instance elsewhere
NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]);
// release the connection, and the data object
[connection release];
[receivedData release];
}
как я могу изменить эту строку для использования connectionWithRequest: delegate data = [NSURLConnection sendSynchronousRequest: request returnResponse: & response error: & error]; – Naeim
Я редактировал свой пост с примером. –