2012-07-08 77 views
0

我知道這可能聽起來很奇怪,我曾在以前的應用程序中工作,現在在我現在的應用程序不能讓它使用相同的代碼工作。我試着展現警報查看只有一次,當應用程序啓動uisng:UIAlertView顯示一次

if (![@"1" isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:@"alert"]]){ 

    [[NSUserDefaults standardUserDefaults] setValue:@"1" forKey:@"alert"]; 
    [[NSUserDefaults standardUserDefaults] synchronize]; 
} 



UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"title" message:@"Text here" delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil]; 

[alert show]; 

會有人心中檢查櫃面我做了一些愚蠢的在這裏,我有交叉檢查的話對我的應用程序在那裏,這是工作,一切似乎一樣。

回答

5

顯示警報,如果塊

if (![@"1" isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:@"alert"]]){ 

    [[NSUserDefaults standardUserDefaults] setValue:@"1" forKey:@"alert"]; 
    [[NSUserDefaults standardUserDefaults] synchronize]; 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"title" message:@"Text here" delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil]; 

    [alert show]; 

} 

或內部使用

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"alertShownOnce"] == NO) 
{ 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"title" message:@"Text here" delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil]; 
    [alert show]; 
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"alertShownOnce"]; 
    [[NSUserDefaults standardUserDefaults] synchronize]; 
} 
+0

當然!非常感謝你,快速回復 - 排序! – JSA986 2012-07-08 20:22:12

+0

我會等9分鐘才能讓我接受答案,它沒有考慮到你的照明快速反應:-) – JSA986 2012-07-08 20:24:55