我有一個UILongPressGestureRecognizer添加到UITextField中。當我按下UITextField時,它顯示我警覺,但這是三個警告給我看。 這是我的代碼:UILongPressGestureRecognizer在Textfield上顯示警報
- (void)viewDidLoad
{
[super viewDidLoad];
UILongPressGestureRecognizer *gs = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(AlertServer:)];
gs.delegate = self;
[_companyidTxt addGestureRecognizer:gs];
[gs release];
}
-(void)AlertServer:(UILongPressGestureRecognizer *)gs
{
alertView = [[UIAlertView alloc] initWithTitle:@"Server" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Okay", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
myTextField = [alertView textFieldAtIndex:0];
myTextField.text=mainString;
[alertView show];
[alertView release];
[alertView retain];
}
誰能解釋爲什麼出現這種情況,以及如何預防? Thanx
重複:http://stackoverflow.com/questions/3319591/uilongpressgesturerecognizer-gets-called-twice-when-pressing-down和內容:HTTP://計算器。 com/questions/3243812/uilongpressgesturerecognizer-問題和這:http://stackoverflow.com/questions/15306942/uialertview-alert-repeat-three-times-within-long-press-gesture-recognizer?rq=1和這個: http://stackoverflow.com/questions/15727203/longpress-on-iphone-app-opens-3-alerts-alertview-or-gesture-code-issue?rq=1請在查詢之前檢查其他問題。 – fishinear