2012-10-31 5 views
0

사용자가 앱을 실행할 때 표시되는 간단한 UIAlertView이 있습니다. 이 구조는 다음과 같습니다.UIAlertView가 여러 번 표시됩니다.

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Welcome!", "") 
               message:NSLocalizedString(@"This is a welcome message.", "")        
               delegate:nil 
             cancelButtonTitle:@"OK" 
             otherButtonTitles: nil]; 
[alert show]; 
[alert release]; 

질문은, 예를 들어 매 5 회마다 표시하도록 사용자 정의 할 수 있습니까?

int runCount = [[NSUserDefaults standardUserDefaults] integerForKey:@"AppRunCount"] + 1 

[[NSUserDefaults standardUserDefaults] setInteger:runCount forKey:@"AppRunCount"]; 

if (runCount <= 5) { 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Welcome!", "") 
              message:NSLocalizedString(@"This is a welcome message.", "")        
              delegate:nil 
            cancelButtonTitle:@"OK" 
            otherButtonTitles: nil]; 
    [alert show]; 
    [alert release]; 
} 
는 는

당신은 viewDidLoad에 위의 코드를 추가 할 수 있습니다, 사전에

감사)

+0

'매 5 회 실행 '- 앱 실행을 5 회마다 시작한다는 의미입니까? – CAMOBAP

+0

"매 5 회 실행"에 대해 좀 더 명확하게 표현할 수 있습니까? – mozkarakoc

+0

그래, 매 5 회 앱 시작 실행;) viewDidLoad에 있습니다. – Icarox

답변

1

당신은 (당신이 당신의 자신의 키 이름을 도입 할 수 있습니다) 키를 AppRunCount에 대한 계산 스토어 앱 실행에 NSUserDefaults을 사용할 수 있습니다

+0

좋습니다는 완벽하게 작동합니다. 이제 앱이 시작될 때마다 알림이 첫 번째, 6 번째, 11 번째 ...에 표시되도록하려면 어떻게해야합니까? – Icarox

+0

'if'-statement의 조건을'runCount <= 5'에서'runCount % 5 == 1'로 바꿉니다. – CAMOBAP

+0

굉장 !! 감사합니다 CAMOBAP !!! – Icarox

2

- (void)applicationDidBecomeActive:(UIApplication *)application 
같은 AppDelegate에 클래스의 방법이있을 것입니다

지금 이제 때마다 응용 프로그램을 만드는 메소드가 호출되고 정수 지금

을 증가합니다 시작이 방법의 한 NSUSerdefaults을 만들고 하나 개의 정수를하고 그 정수를 증가시키고

NSUserdefaults

에 저장하는 경우 그의 조건 방법은 다음과 같습니다.

if(your integer which has nsuserdefaults >=5) 
{ 
    your alertview 
    again here make your nsinteger to Zero which is stored in nsuserdefaults 
    your integer which has nsuserdefaults =0 
} 

이것은 두 번째 질문의 답변입니다. 알림이 팝업됩니다 작동 여부를 알려주세요 .. !!!! 해피 코딩 !!!!

+0

이 너무 작동하고 runCount % 5 == 1 코드를 변경하는 첫 번째도 작동합니다. 감사합니다 NiravPatel – Icarox

+0

당신은 오신 것을 환영합니다 .... 내가 좀 포인트를 가질 수 있을까 ??? !!!! – NiravPatel

관련 문제