2011-03-16 61 views
2

我正在使用验证密钥从使用Wi-Fi的服务器下载内容。如果许可证密钥错误或无法使用Wi-Fi,我需要显示UIAlert。我已经写了显示警报视图的警报,但警报没有被显示......这是把我的脑袋里流出的血液......任何人都可以帮忙......控制权正在通过这条线,但仍然是警报没有被显示。无法在我的应用程序中显示UIAlertView

-(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];  
} 

}

+1

您是否尝试过使用非零消息? – malinois 2011-03-16 14:47:42

+0

是的,我已经尝试过,但我仍然运气不佳.... – 2011-03-16 14:49:32

+0

日志显示? – malinois 2011-03-16 14:51:10

回答

5

您是否试图在从主线程以外的线程调用的方法中显示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]; 
} 

,然后更改的最后else子句在当前的代码,以便它使用:

[self performSelectorOnMainThread:@selector(showAlert) withObject:nil waitUntilDone:NO]; 

更多请见NSObject class reference有关performSelectorOnMainThread:方法的信息。

+0

我刚才试过它格雷格,但即使这是ont工作... – 2011-03-16 15:06:45

+0

请看我的更新问题格雷格...我已经把整个方法的问题 – 2011-03-16 15:36:34

+0

您更新的代码仍然没有使用performSelectorOnMainThread来显示警报视图。 – Greg 2011-03-17 17:23:46

0

你所创建的警报,你可以检查在警报变量NULL指针后? 也许你需要指定一条消息?除此之外,我无法看到您发布的代码有任何问题。

+0

我无法理解这一点詹姆斯...我的意思是你可以请告诉我什么是检查NULL警报变量中的指针?你是在谈论我传递给消息列的nil值? – 2011-03-16 14:58:17

+1

他意味着在创建警报的行后面设置一个断点,当它到达时,将鼠标放在警报变量上并查看它是否指向nil。如果你不知道如何使用断点,用NSLog以编程方式检查它(alert?@“not nil”:@“nil”); – 2011-03-16 15:15:27

+0

ooh: - )...我做了它zaky .... itz不为零..警报的值是0x65930cO .....任何线索? – 2011-03-16 15:30:22

相关问题