A f*_*pha 2 iphone uialertview ipad
在我的应用程序中,我使用验证密钥从服务器使用Wi-Fi下载内容.如果许可证密钥错误或wi-fi不可用,我需要显示UIAlert.我已经写了一个显示警报视图的男女同校,但警报没有显示......这让我的脑子里流下了鲜血......任何人都可以帮忙......控制权正在越过这条线,但仍然是警报未显示.
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory= [[[UIApplication sharedApplication] delegate] applicationDocumentsDirectory]; //[pathToStore objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingFormat:@"packages"];
NSString *packagePath = [NSString stringWithFormat:@"%@/%@", path,isbnTemp];
[recievedData writeToFile:[documentsDirectory stringByAppendingPathComponent:@"file.zip"] atomically:YES];
NSString *zipPath=[documentsDirectory stringByAppendingPathComponent:@"file.zip"];
[fileManager createDirectoryAtPath:documentsDirectory withIntermediateDirectories:NO attributes:nil error:nil];
ZipArchive *zipArchive = [[ZipArchive alloc]init];
if([zipArchive UnzipOpenFile:zipPath]){
if([zipArchive UnzipFileTo:packagePath overWrite:YES]){
[self loadContent];
}
else{
NSLog(@"Unable to UnArchieve the packages");
}
}
else {
NSLog(@"Failure To Open Archive");
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Your ISBN and/or Licence Key are incorrect" message:Nil delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alert show];
[alert release];
}
Run Code Online (Sandbox Code Playgroud)
}
您是否尝试在从主线程以外的线程调用的方法中显示UIAlertView?例如,如果您尝试在异步回调中显示UIAlertView,它可能在单独的线程上运行.
如果是这样,您需要将显示UIAlertView的代码移动到单独的选择器,并使用其中一种performSelectorOnMainThread:方法在主线程上调用它.
例如,将以下方法添加到您的类:
-(void)showAlert {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Your ISBN and/or Licence Key are incorrect" message:Nil delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alert show];
[alert release];
}
Run Code Online (Sandbox Code Playgroud)
然后更改当前代码中的最后一个else子句,以便它使用:
[self performSelectorOnMainThread:@selector(showAlert) withObject:nil waitUntilDone:NO];
Run Code Online (Sandbox Code Playgroud)
有关方法的更多信息,请参阅NSObject类参考performSelectorOnMainThread:.
| 归档时间: |
|
| 查看次数: |
1714 次 |
| 最近记录: |