系统键盘在ios7 ios8上不同效果

来源:互联网 发布:手机登不了淘宝怎么办 编辑:程序博客网 时间:2024/05/29 11:50

今天写项目的时候遇到一个问题:从A界面推出B界面,B界面的textField编辑完成之后,向服务器发送编辑数据之后,成功之后弹出成功的系统提示框。代码如下:

//B界面的textfiled编辑完成点击okButton:

但这种情况在ios7 中没有出现,在ios8以上会出现:

- (void)OKButtonBeclick

{

    __weakVFeedbackViewController *weakSelf = self;

    [self.view endEditing:YES];

    self.button.enabled =NO;

    

    [[VFeedBackManagersharedManagerFeedBackWithcontent:self.feedbackTextView.textsuccess:^{

        [UIAlertViewshowWithTitle:@"Thanks for your feedback" message:nilcancelButtonTitle:nil otherButtonTitles:@[@"OK"]tapBlock:^(UIAlertView *alertView,NSInteger buttonIndex) {

            if (buttonIndex == 0) {

                   [weakSelf.navigationControllerpopViewControllerAnimated:YES];  

            }

        }];

    } failure:^(NSString *failing) {

        weakSelf.button.enabled =YES;

        NSLog(@"%@",failing);

    }];

}


直接这样写的话会遇到一个问题:就是界面先返回,然后键盘会在A界面出现下落的状况。因为AlertView 的 block不是在主线程里面,所以会会执行先执行

 [weakSelf.navigationController popViewControllerAnimated:YES];  然后执行 [self.view endEditing:YES];

解决方案是进行延迟:等[self.view endEditing:YES]执行完毕,再执行AlertView 的 block 中得 [weakSelf.navigationController popViewControllerAnimated:YES]; 

延迟一段时间,等主线完成,待执行线程的函数

合理的代码是:加dispatch_after的延迟函数

- (void)OKButtonBeclick

{

    __weakVFeedbackViewController *weakSelf = self;

    [self.view endEditing:YES];

    self.button.enabled =NO;

    

    [[VFeedBackManagersharedManagerFeedBackWithcontent:self.feedbackTextView.textsuccess:^{

        [UIAlertViewshowWithTitle:@"Thanks for your feedback" message:nilcancelButtonTitle:nil otherButtonTitles:@[@"OK"]tapBlock:^(UIAlertView *alertView,NSInteger buttonIndex) {

            if (buttonIndex == 0) {

                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

                   [weakSelf.navigationControllerpopViewControllerAnimated:YES];  

                });

               

            }

        }];

    } failure:^(NSString *failing) {

        weakSelf.button.enabled =YES;

        NSLog(@"%@",failing);

    }];

}







0 0