//下面这一句代码常常卸载网络请求的线程中,须要利用主线程来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]; }];