//下面這一句代碼常常卸載網絡請求的線程中,須要利用主線程來geng'xin更新UI。 //再網路開發中,很容易出現問題的地方就是忘記在主線程中更新UI dispatch_async(dispatch_get_main_queue(), ^{ UIAlertView *aleart = [[UIAlertView alloc]initWithTitle:@"提示" message:@"網絡不給力" delegate:self cancelButtonTitle:@"肯定" otherButtonTitles:nil, nil]; [aleart show]; });
//上面的是使用GCD方式,也可使用另外一種方式 NSOPerationQueue是對GCD的封裝 [[NSOperationQueue mainQueue] addOperationWithBlock:^{ UIAlertView *aleart = [[UIAlertView alloc]initWithTitle:@"提示" message:@"網絡不給力" delegate:self cancelButtonTitle:@"肯定" otherButtonTitles:nil, nil]; [aleart show]; }];