作者freejer (.....)
看板MacDev
标题Re: [问题] TextField 放入alert里面导致键盘无法收回
时间Tue Jul 19 21:04:36 2011
借发问一下
我也有一样的问题
在.h中已加入UITextFieldDelegate
并宣告 UITextField *field;
在.m中
- (BOOL)textFieldShouldReturn(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
- (void)willPresentAlertView(UIAlertView *)alertView
{
CGRect frame = alertView.frame;
if(alertView==alert_message)
{
frame.origin.y -= 120;
frame.size.height += 80;
alertView.frame = frame;
}
//加入自订的label及UITextFiled
field= [[UITextField alloc] initWithFrame: CGRectMake( 30,70,217, 30 )];
field.borderStyle=UITextBorderStyleRoundedRect;
[alertView addSubview:field];
field.delegate=self;
field.returnKeyType=UIReturnKeyDone;
}
奇怪的是
中断点都有跑进 [textField resignFirstResponder];
但无法执行就是无法执行
请各位指点
谢谢
※ 引述《markzog21 (残羽星辰)》之铭言:
: 如题
: -(BOOL) textFieldShouldReturn:(UITextField *) textField
: {[textField resignFirstResponder]
: [textField becomeFirstResponder];
: //[(UIAlertView *)[textField superview] dismissWithClickedButtonIndex:1 animated:YES];
: [myAlertView show];
: return YES;
: //[accoutPassword resignFirstResponder];
: //return YES;
: }
: 网路上是说textFieldShouldReturn:(UITextField *) textField就可以
: 但是测试发现alert里面放下field以後叫出的键盘
: 似乎不适用这个function
: 因为按下retrun键无进入此function
: 好像是delegate的问题但不知如何修改delegate.....
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 111.240.183.240