2012-03-06 2 views
0

재설정 버튼이있는 응용 프로그램의 카운터가 있지만 탭 한 후 즉시 재설정하는 대신 UIAlertView를 팝업으로 표시하고 사용자가 경고의 단추로 재설정을 다시 시작하게하십시오. 나는 이것에 대해 전반적으로 잘 경험하지 못했기 때문에 아래 코드를 추가/대체하는 것만으로도 충분할 것입니다. 나는이 롤에서 일하고있다. 어떤 도움을 주셔서 감사합니다!UAlertView 내에서의 동작 4.3

- (IBAction)reset { 
    UIAlertView *alert = [[UIAlertView alloc] 

          initWithTitle:@"titleHere" 
          message:@"messageHere" 
          delegate: self 
          cancelButtonTitle:@"Cancel" 
          otherButtonTitles:@"Reset", nil]; 
    alert.tag = TAG_RESET; 
    [alert show]; 
} 

-(void)alertView:(UIAlertView *)alertView 
clickedButtonAtIndex:(NSInteger)buttonIndex { 
    if (alertView.tag == TAG_DEV) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.examplesite.com"]]; // just another alert don't worry about this one 
    } else if (alertView.tag == TAG_RESET) { // i need help here   
    } 
} 

경고 내에서 기본적으로 IBAction입니다.

UPDATE : 가 어떻게 버튼이 통합 것인가?

-(IBAction)zero { 
    counter=0; 
    count.text = [NSString stringWithFormat:@"%i",counter]; 
} 

UPDATE2는 :

그래서 지금은 완벽하게 수를 지 웁니다이, 한, 유일한 문제는이 탭 중 하나를 취소하거나 재설정 후 경고 팝업 계속 지금 ...

-(IBAction)resetButtonPushed { 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"titleHere" 
                message:@"messageHere" 
                delegate:self 
              cancelButtonTitle:@"Cancel" 
              otherButtonTitles:@"Reset", nil]; 
    alert.tag = TAG_RESET; 
    [alert show]; 
} 

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ 
    if (alertView.tag == TAG_DEV){ 
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.examplesite.com"]]; // just another alert don't worry about this one 
    } 
    else if (alertView.tag == TAG_RESET) { [self resetButtonPushed]; { 
     counter=0; 
     count.text = [NSString stringWithFormat:@"%i",counter]; 
    }  if ([[alertView buttonTitleAtIndex:buttonIndex] isEqualToString:@"Reset"]){ 
     // Reset button tapped 
     } 
    } 
} 
+1

나는 당신이 성취하려는 것을 이해하지 못합니다. reset 메소드는 UI에서 버튼을 누를 때 호출됩니다. 재설정 단추가있는 경고를 표시합니다. 사용자가 해당 버튼을 누르면 clickedButton 콜백이 호출됩니다. if (alertView.tag == TAG_RESET)에서 재설정이 눌려 졌음을 알고 있으므로이 시점에서 카운터를 지 웁니다. 내가 뭘 놓치고 있니? –

+0

NJones가 얻은 것을 거의 시도하고 있습니다. – DiscoveryOV

답변

0
나중에 혼란하게 될 코드를 찾고있을 때 내가 IBAction 같은 zero 마킹 기능에 무리를 줄 것이다

.

재설정 방법의 이름도 혼동을 줄 수 있습니다. 나는 좀 더 기술적 인 이름을 제안 할 것이다. 또한 표준 IBAction 메서드를 사용하여 보낸 사람 매개 변수를 가져 오는 방법도 있습니다. 그래서 같이 :

-(IBAction)resetButtonPushed:(id)sender { 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"titleHere" 
                message:@"messageHere" 
                delegate: self 
              cancelButtonTitle:@"Cancel" 
              otherButtonTitles:@"Reset", nil]; 
    alert.tag = TAG_RESET; 
    [alert show]; 
} 

당신이 콜백을 기다리고의 UIAlertViewDelegate 패러다임을 잘 알고있는 것 같다. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex을 사용하고 있으므로 clickedButtonAtIndex:(NSInteger)buttonIndex 매개 변수를 위임 메서드에 전달해야합니다. 그래서 같이 : 응답이 섹션은 당신이 방법을 이해하는 데 문제가있는 이유는 확실하지 않다

의견을

if ([[alertView buttonTitleAtIndex:buttonIndex] isEqualToString:@"Reset"]){ 
    // Reset button tapped 
} 

: 또는

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ 
    if (alertView.tag == TAG_DEV){ 
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.examplesite.com"]]; // just another alert don't worry about this one 
    } 
    else if (alertView.tag == TAG_RESET) { 
     if (buttonIndex == alertView.cancelButtonIndex){ 
      // reset alert cancel button was tapped 
     } 
     else { 
      // Reset button tapped 
     } 
    } 
} 

당신이 뭔가를 할 수 zero 방법으로 전화하십시오. 나는 그것이 IBAction이라는 용어가 불필요하게 산만 해지고 있기 때문이라고 생각합니다. IBActionvoid을 말하는 또 다른 방법입니다. 유일한 차이점은 IBAction 인터페이스 빌더를 사용하면 메소드가 "보입니다"입니다. 코드에 관한 한, 다음의 두 가지 메소드 정의가 동일합니다.

-(void)zero; 
-(IBAction)zero; 

다시 나는 또한 IBAction에와 더 자세한 설명 방법 이름을 권합니다. 아마 같은 것을 : 당신은 물론, 다른 모든처럼이 메소드를 호출 할

-(void)zeroTheCounter { 
    counter=0; 
    count.text = [NSString stringWithFormat:@"%i",counter]; 
} 

는 위의 예에서 컨텍스트에서 사용할 수 있습니다.

 else { 
      // Reset button tapped 
      [self zeroTheCounter]; 
     } 

응답에 물론 "편집 2" 또 다른 경고보기를 보여줍니다, 당신은 alertview 위임 방법에 [self resetButtonPushed] 호출로로 부탁드립니다.

이 편집은 현재 질문에있는 코드를 사용합니다.

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ 
    if (alertView.tag == TAG_DEV){ 
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.examplesite.com"]]; // just another alert don't worry about this one 
    } 
    else if (alertView.tag == TAG_RESET) { 
     //[self resetButtonPushed]; { calling this will cause another alertview. 
        //counter=0; this is done is zero 
        //count.text = [NSString stringWithFormat:@"%i",counter]; this is done in zero 
     //} 
     if ([[alertView buttonTitleAtIndex:buttonIndex] isEqualToString:@"Reset"]){ 
         // Reset button tapped 
      [self zero]; 
        } 
    } 
} 
+0

원래 질문에서 업데이트를 확인하십시오. – DiscoveryOV

+0

@ R3TRI8UTI0N 나는 나의 대답에 그것을 추가했다, 나는 그것이 물건을 깨끗이하기를 바란다. – NJones

+0

업데이트 된 질문 : UPDATE2 : 그런데 도움을 주셔서 감사합니다. – DiscoveryOV