- (void)viewDidLoad {
_textField1 = [[UITextField alloc] initWithFrame:CGRectMake(30, 150, 250, 40)];
_textField1.delegate = self;
_textField1.placeholder = @"text1";
[self.view addSubview:_textField1];
UIButton *alertBtn = [[UIButton alloc] initWithFrame:CGRectMake(100, 200, 40, 30)];
alertBtn.backgroundColor = [UIColor redColor];
[self.view addSubview:alertBtn];
[alertBtn addTarget:self action:@selector(alertTapped) forControlEvents:UIControlEventTouchUpInside];
[self addTextField];
}
- (void)alertTapped
{
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Title"
message:@"Message"
delegate:nil
cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
[myAlertView setAlertViewStyle:
UIAlertViewStyleSecureTextInput];
[myAlertView setDelegate:self];
[myAlertView show];
}
只要textfield里面有字,一点button 就会崩溃。
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The layout constraints still need update after sending -updateConstraints to <_UIKeyboardLayoutAlignmentView: 0x137d46830; frame = (0 0; 0 0); userInteractionEnabled = NO; layer = <CALayer: 0x170226d60>>.
_UIKeyboardLayoutAlignmentView or one of its superclasses may have overridden -updateConstraints without calling super. Or, something may have dirtied layout constraints in the middle of updating them. Both are programming errors.'
*** First throw call stack:
(0x1826682d8 0x193e3c0e4 0x182668218 0x18776c748 0x18776c880 0x182548cdc 0x18776c620 0x18776c880 0x182548cdc 0x18776c620 0x18776c880 0x1871a37b4 0x1834c9308 0x1871a34d0 0x1871bfe04 0x18776cbe4 0x1870ba140 0x187579bd0 0x1873b0fb0 0x18712c240 0x18709c6ec 0x1826202a4 0x18261d230 0x18261d610 0x1825492d4 0x18bd676fc 0x18710efac 0x100062a18 0x1944baa08)
libc++abi.dylib: terminating with uncaught exception of type NSException
我用了你贴的代码,是没有问题的,但是我注释了“[self addTextField];”这行代码,因为你没把方法贴出来。
或许你可以把完整的代码贴上来(或Demo)。