2011-01-03 4 views
1

태그를 사용하여 UIAlertView에 액세스하려고합니다. 코드는태그를 사용하여 UIAlertView에 액세스 할 수 있습니까?

UIAlertView *a=(UIAlertView *)[self.view viewWithTag:presetTag]; 

아래에 보여하지만 반환하지 객체 (0x0으로)

나는 나의의 UIViewController에 대한 참조를 생성하지 않고 표시되는 UIAlertView 객체에 대한 포인터를 얻을 수있는 방법을 찾기 위해 찾고 있어요 클래스를 표시하고 있습니다. 나는 UIAlertView를 생성하고 태그 속성에 상수가 아닌 0 값을 할당 한 다음,이를 통해 표시하고 UIAlertView 참조를 해제합니다.

경고보기의 단추 중 하나를 건드리지 않는 다른 이벤트를 기반으로 경고보기를 숨기려면이 방법이 유용 할 수 있습니다. 서버에서 경고가 더 이상 유효하지 않다는 것을 앱에 알리므로 경고보기에서 버튼 색인 -1을 눌러 닫습니다. 그러나 그 경고에 대한 언급이 없으므로 어떻게 찾을 수 있습니까?

어떤 의견을

감사

InterDev에서 오신 것을 환영합니다

답변

-2

이 당신이 필요로하는 무엇인가? 특히, 프로토콜 콜백 메소드에서 태그 속성을 통해 각 UIAlertView의 태그 정보에 액세스 할 수 있습니다.

@protocol UIAlertViewDelegate <NSObject> 
@optional 

// Called when a button is clicked. The view will be automatically dismissed after this call returns 
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex; 

// Called when we cancel a view (eg. the user clicks the Home button). This is not called when the user clicks the cancel button. 
// If not defined in the delegate, we simulate a click in the cancel button 
- (void)alertViewCancel:(UIAlertView *)alertView; 

- (void)willPresentAlertView:(UIAlertView *)alertView; // before animation and showing view 
- (void)didPresentAlertView:(UIAlertView *)alertView; // after animation 

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex; // before animation and hiding view 
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex; // after animation 

@end 
+0

아니, 나는 viewcontroller에서 alertview에 직접 액세스하기를 바란다. – arachide

-1

나는 그것을, 당신은 태그에 아닌 값을 설정하는 것을 확인하십시오 가능하다고 생각.

2

UIAlertView은 앱의 기본 계층 인 UIView에 포함되지 않은 UIWindow을 만듭니다. 따라서 [UIView viewWithTag:]을 사용하여 찾을 수 없습니다.

나중에 다시 찾으려면 작성한 UIAlertView에 포인터를 저장해야합니다.

앱에서 UIAlertView에 액세스하는 방법이 있습니다. 그런 다음 태그를 사용하여 찾고자하는 것을 확인할 수 있지만 앱의 내부 구조에 의존하므로 중지 할 수 있습니다. 가능성은 낮지 만 iOS의 차기 버전에서 작업합니다. 관심이 있으시면 see this other SO response으로 연락하십시오.

4

UIAlertView는 응용 프로그램의보기 계층에 속해 있지 않으므로 사전에 인스턴스를 만든 직후에 인스턴스를 저장하면 나중에 인스턴스를 검색 할 수 있습니다.

뭔가 같은 :

[_alertIndex removeObjectForKey:[NSNumber numberWithInt:kMy_TAG]]; 
: 당신이 볼 수있는 완료하면

UIAlertView *alert = [_alertIndex objectForKey:[NSNumber numberWithInt:kMy_TAG]]; 

것은 사전에서 제거해야합니다 :

UIStateAlertView *alert = [[UIStateAlertView alloc] 
          initWithTitle:@"my_message" 
          message:nil 
          delegate:self 
          cancelButtonTitle:@"Cancel" 
          otherButtonTitles: nil]; 
alert.tag = kMY_TAG; 
[_alertIndex setObject:alert forKey:[NSNumber numberWithInt:kMy_TAG]]; 
[alert show]; 
[alert release]; 

이 경고를 검색 할

_alertIndex는 NSMutableDictionary

iPhone SDK: check if a UIAlertView is showing은 해결책을 제공하지만, Apple이 내부 업무를 수행하는 방식에 의존하고 있으며 언제든지 중단 될 수 있습니다. 그래서 피해야한다

관련 문제