AlertView虽好 但是BUG却不少 尤其是在iOS8的时候 最明显
这时候我们用ALertControll
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"通知内容将不会被保存" message:@"确定丢弃此通知?" preferredStyle:UIAlertControllerStyleAlert];
然后配合UIalertAction 做出来一个AlertView
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
}];
UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"丢弃" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[self.navigationController popViewControllerAnimated:YES];
}];
然后组合在一起
[alertController addAction:cancelAction];
[alertController addAction:otherAction];
[self presentViewController:alertController animated:YES completion:^{
}];
OK 搞定了
限制textField的字符串长度
很简单 掉一个方法就好了
#pragma mark - 输入长度校验
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string];
//邮箱和手机
if (self.phoneTextField == textField){
if ([toBeString length] > 11) {
return NO;
}
}
//验证码
if (self.securitycodeTextField == textField){
if ([toBeString length] > 6) {
return NO;
}
}
return YES;
}