uialertview를 무시하지 않을 수 있습니까?
-
20-09-2019 - |
문제
uialertViewDelegate 프로토콜에는 다음을 포함한 몇 가지 선택 방법이 있습니다.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
이것은 모든 버튼 클릭이 실제로 경고보기를 무시하지는 않다는 것을 암시하는 것 같습니다. 그러나 버튼 누름을 사용하여 자동으로 무시하지 않도록 경고보기를 구성하는 방법이 없습니다.
이것을 달성하기 위해 서브 클래스를 만들어야합니까?
UialertViewDelegate 프로토콜이 다음과 같은 이유는 무엇입니까?
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
그리고
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
선택적으로 지원하지 않은 경우 각 버튼 클릭마다 경고보기를 해제하지 않습니까?
간단한 따로 : 나는 Uialertview가 무엇을 위해 설계된 것을 알고 있습니다. 그러나 내 목적은 앱이 종료되기 전에 사용자가 페이스트 보드에 일부 텍스트를 복사 할 수 있도록하는 것입니다 (경고보기가 기각 될 때 자동으로 발생합니다.
해결책
예. 아강 UIAlertView
그리고 과부하 -dismissWithClickedButtonIndex:animated:
, 예를 들어
@implementation MyAlertView
-(void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated {
if (buttonIndex should not dismiss the alert)
return;
[super dismissWithClickedButtonIndex:buttonIndex animated:animated];
}
@end
비공식적으로 당신은 a를 정의 할 수 있습니다
-(void)alertSheet:(UIAlertSheet*)sheet buttonClicked:(id)button;
대의원에게 우회 할 수있는 방법 -dismissWithClickedButtonIndex:animated:
, 그러나 그것은입니다 문서화되지 않은, 그래서 나는 그것이 당신에게 적합한 지 모르겠습니다.
다른 팁
willPresentAlertView:
, didPresentAlertView:
, alertView:willDismissWithButtonIndex:
, 그리고 alertView:didDismissWithButtonIndex:
Uialertview의 애니메이션의 시작과 끝을 추적하기위한 것입니다.
UialertView의 애니메이션을 추적 할 필요가없는 응용 프로그램은 단순히 사용할 수 있습니다. alertView:clickedButtonAtIndex:
. 이 방법의 문서는 "이 방법이 호출 된 후에 수신기가 자동으로 해산된다"고 말합니다.
제 생각에는 AlertView를 유지할 이유가 없습니다. 당신이 그것을 지키고 싶더라도, 참조를 유지하여 "다시 쇼어"에 대해 생각하고 [alertview show] ==>에 전화하십시오. 서브 클래스 할 필요가 없습니다. 좋은 소식, 응?
경고
일부 소스에서 나는이 프로세스에 따라 거의 앱이 거부되었다고 들었습니다. iOS6 동안 제 경우에는 운이 좋았으므로 여기에 코드가 표시됩니다. 자신의 위험에 따라 사용하십시오 :-/
서브 클래싱이 가장 좋은 방법입니다. a bool
경고를위한 깃발은 유지 여부에 관계없이.
이것은 서브 클래스입니다 UIAlertView
//
// UICustomAlertView.h
//
#import <UIKit/UIKit.h>
@interface UICustomAlertView : UIAlertView
{
}
@property(nonatomic, assign) BOOL dontDisppear;
@end
//
// UICustomAlertView.m
//
#import "UICustomAlertView.h"
@implementation UICustomAlertView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated {
if(self.dontDisppear)
return;
[super dismissWithClickedButtonIndex:buttonIndex animated:animated];
}
@end
그리고 이것이 제 코드에 사용한 방법입니다.
if(![txtUsername.text isEqualToString:@"admin"] && ![txtPassword.text isEqualToString:@"admin"])
{
alertLogin.dontDisppear = YES;
alertLogin.message = NSLocalizedString(@"my_alert", nil);
}
else
{
alertLogin.dontDisppear = NO;
// proceed
}
#import "MLAlertView.h"
@implementation MLAlertView
-(void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated {
}
-(void)dismissNow:(NSInteger)buttonIndex {
[super dismissWithClickedButtonIndex:buttonIndex animated:YES];
}