【问题标题】:UILongPressGestureRecognizer Show Alert On TextfieldUILongPressGestureRecognizer 在文本字段上显示警报
【发布时间】:2013-11-11 02:34:19
【问题描述】:

我有一个 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];
}

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

【问题讨论】:

标签: ios iphone ios4 uigesturerecognizer uialertview


【解决方案1】:

根据您的观察更改您的longPressGestureRecognizer.minimumPressDuration(时间间隔以秒为单位。默认持续时间为 0.5 秒。)或使用一些标志来检查是否已显示警报。

【讨论】:

    【解决方案2】:

    试试这个,

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多