【问题标题】:After iOS 8.1, on all devices ScrollView goes upwards and not scrolling when tapping on alertview cancel button在 iOS 8.1 之后,在所有设备上,当点击 alertview 取消按钮时,ScrollView 向上并且不滚动
【发布时间】:2015-08-18 22:10:33
【问题描述】:

我有一个登录屏幕,其中有两个用于用户名和密码的文本字段。当电子邮件不正确时,我向下移动键盘并向用户显示适当的警报。当我单击警报视图的取消按钮时,警报视图消失并且滚动视图向上。此问题仅出现在 iOS 8.1 之后的设备上。在 iOS 8.1 及更早版本上,它运行良好。不明白具体原因是什么?下面是代码

-(BOOL)textFieldShouldReturn:(UITextField *)textField{

    if (txtActiveField == txtUsername) {
        [txtPassword becomeFirstResponder];
    }
    else if (txtActiveField == txtPassword) {
        [txtPassword resignFirstResponder];
        //[self loginViaEmail:self];
        [self performSelector:@selector(loginViaEmail:) withObject:btnLogin afterDelay:0.0];
    }

    return YES;}

-(IBAction)loginViaEmail:(id)sender{

    //[txtActiveField resignFirstResponder];
    if ([[txtUsername.text stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" "]] length] == 0)
    {
        [AppDelegate showWithTitle:title message:@"Please enter Username/Email for your account"];
    }
    else if ([txtPassword.text length] < 6)
    {
        if([[txtPassword.text stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" "]] length] == 0)
            [AppDelegate showWithTitle:title message:@"Please enter Password"];
        else
            [AppDelegate showWithTitle:title message:@"Password contain minimum 6 characters"];
    }


#pragma mark Show alert with message
+(void)showWithTitle:(NSString *)title message:(NSString *)msg
{

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
}

【问题讨论】:

    标签: ios objective-c iphone uiscrollview ios8.3


    【解决方案1】:

    我认为这是警报视图的问题。从 iOS 8 开始,AlertViewController 代替了警报视图。尝试使用以下代码,它在 iOS 8.4 及以下版本上运行良好

    if (IS_OS_8_OR_LATER) {
            UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];
    
            UIAlertAction *cancelAction = [UIAlertAction
                                         actionWithTitle:@"OK"
                                         style:UIAlertActionStyleCancel
                                         handler:^(UIAlertAction *action)
                                         {
    
                                         }];
            [alertVC addAction:cancelAction];
    
            [[[[[UIApplication sharedApplication] windows] objectAtIndex:0] rootViewController] presentViewController:alertVC animated:YES completion:^{
    
            }];
        }
        else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
            [alert show];
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-06
      • 2023-01-11
      • 2021-12-26
      • 2016-04-04
      相关资源
      最近更新 更多