當您將數據傳輸到服務器指示器活動時,我的應用程序在您服務器之後將數據發送到服務器。當指標隱藏時,我試圖顯示數據成功發送的警報。但是當我嘗試撤消警報時,應用程序就會崩潰。可能是什麼問題?謝謝!活動指示器和警報
- (void)viewDidLoad
{
[super viewDidLoad];
activityIndicator = [[UIActivityIndicatorView alloc] init];
activityIndicator.frame = CGRectMake(140, 190, 37, 37);
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[self.view addSubview:activityIndicator];
}
- (IBAction)sendForm:(id)sender {
[self performSelectorInBackground:@selector(loadData) withObject:activityIndicator];
[activityIndicator startAnimating];
}
-(void)loadData {
NSURL *scriptUrl = [NSURL URLWithString:@"http://zav333.ru/"];
NSData *data = [NSData dataWithContentsOfURL:scriptUrl];
if (data)
{
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://zav333.ru/sushi.php"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:15.0];
request.HTTPMethod = @"POST";
// указываем параметры POST запроса
NSString* params = [NSString stringWithFormat:@"name=%@&phone=%@&date=%@&howmuchperson=%@&smoke=%@ ", self.name.text, self.phone.text, self.date.text, self.howmuchperson.text, self.smoke];
*howMuchPerson, *smoke;
request.HTTPBody =[params dataUsingEncoding:NSUTF8StringEncoding];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[activityIndicator stopAnimating];
UIAlertView* ahtung = [[UIAlertView alloc] initWithTitle:@"Спасибо" message:@"Ваша заявка принята!\nВ течение часа, Вам поступит звонок для подтверждения заказа" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[ahtung show];
}
}
什麼記錄顯示。 – Dilip 2013-02-16 10:39:13
crash log/stack trace plz – 2013-02-16 10:44:06
爲什麼不嘗試在主線程中運行UIAlertView和[activityIndicator stopAnimating]。 – 2013-02-16 10:53:48