gpt4 book ai didi

ios - UILongPressGestureRecognizer 在文本字段上显示警报

转载 作者:行者123 更新时间:2023-11-29 03:31:34 27 4
gpt4 key购买 nike

我已将 UILongPressGestureRecognizer 添加到 UITextField 中。当我按下 UITextField 时,它会向我显示警报,但这是三个警报向我显示。这是我的代码:

- (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];
}

谁能解释一下为什么会发生这种情况,以及如何预防这种情况?提前致谢

最佳答案

试试这个,

-  (void)AlertServer:(UILongPressGestureRecognizer*)sender { 
if (sender.state == UIGestureRecognizerStateEnded) {
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];

}
else if (sender.state == UIGestureRecognizerStateBegan){
NSLog(@"UIGestureRecognizerStateBegan.");
//Do Whatever You want on Began of Gesture
}
}

关于ios - UILongPressGestureRecognizer 在文本字段上显示警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19700559/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com