Iphone 键盘不';不要消失

Iphone 键盘不';不要消失,iphone,objective-c,ipad,Iphone,Objective C,Ipad,我以编程方式将uitextfield添加到uitableview单元格中,问题是当我在文本字段中键入并单击“完成”或从文本字段中移动时,键盘不会消失 有解决这个问题的建议吗 @interface test_20110605ViewController : UIViewController <UITextFieldDelegate> { UITextField *PtienttextField ; } @property ( nonatomic , retain ) UIT

我以编程方式将uitextfield添加到uitableview单元格中,问题是当我在文本字段中键入并单击“完成”或从文本字段中移动时,键盘不会消失

有解决这个问题的建议吗

@interface test_20110605ViewController : UIViewController <UITextFieldDelegate> {

    UITextField *PtienttextField ;
}

@property ( nonatomic , retain ) UITextField *PtienttextField ;

@end

at m file 

@implementation test_20110605ViewController

@synthesize PtienttextField ;


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];

        if (indexPath.row == 0 && indexPath.section == 1 ) {


            //cell.textLabel.text = "Patient Name";



            UILabel *PatientLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 120, 25)];
            PatientLabel.backgroundColor = [UIColor clearColor];
            PatientLabel.tag = 1;
            PatientLabel.text = @"Patient Name" ; 
            [cell.contentView addSubview:PatientLabel];

            PtienttextField = [[UITextField alloc]initWithFrame:CGRectMake(140, 10, 400, 30)];

            PtienttextField.clearsOnBeginEditing = YES;
            PtienttextField.textAlignment = UITextAlignmentRight;
            PtienttextField.returnKeyType = UIReturnKeyDone;
            PtienttextField.delegate = self;
            //PtienttextField.tag = 2 ; 
            [PtienttextField setBorderStyle:UITextBorderStyleBezel];
            [cell.contentView addSubview:PtienttextField];
        }
    }

    // Configure the cell.

    return cell;
}

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


    return YES;
}

@end
@接口测试\u 20110605ViewController:UIViewController{
UITextField*OptientTextField;
}
@属性(非原子,保留)UITextField*OptientTextField;
@结束
在m文件中
@实现测试\u 20110605ViewController
@合成OptientTextField;
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
静态NSString*CellIdentifier=@“Cell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1重用标识符:CellIdentifier]自动释放];
if(indexPath.row==0&&indexPath.section==1){
//cell.textlab.text=“患者姓名”;
UILabel*PatientLabel=[[UILabel alloc]initWithFrame:CGRectMake(10,10,120,25)];
PatientLabel.backgroundColor=[UIColor clearColor];
PatientLabel.tag=1;
PatientLabel.text=@“患者姓名”;
[cell.contentView addSubview:PatientLabel];
OptientTextField=[[UITextField alloc]initWithFrame:CGRectMake(140,10400,30)];
OptientTextField.clearsOnBeginEditing=是;
OptientTextField.textAlignment=UITextAlignmentRight;
OptientTextField.returnKeyType=UIReturnKeyDone;
PtienttextField.delegate=self;
//PtienttextField.tag=2;
[PtienttextField setBorderStyle:UITextBorderStyleBezel];
[cell.contentView addSubview:PtienttextField];
}
}
//配置单元格。
返回单元;
}
-(BOOL)textField应返回:(UITextField*)textField{
返回YES;
}
@结束

我认为您在textFieldShouldReturn中缺少以下内容:

[textField resignFirstResponder];

然后您的
返回YES

当键盘出现时,尝试放置NSNotification,并将文本字段设置为FirstResponseder。您使用的问题可能是因为textfield不是您案例中的第一个响应程序。

我添加了它,并且出现了相同的问题。但是textfield中的断点或NSLog应该返回,它确实被击中了吗?然后它真的应该响应。。。在textField shouldReturn:方法的开头尝试if([textField isKindOfClass:[UITextField class]]),并在其中设置一个断点。我这样做了,它输入if语句并键入nslog ny other suggestionKay,研究添加一个目标,就像您通常对这种类型的对象所做的那样:[textField addTarget:self action:@selector(myMethodToHit:)forControlEvents:uicontrolEventEditingDidenoNexit];在创建textfield对象后立即添加此项。在myMethodToHit中,将其替换为您的textFieldShouldReturn:,或者编写一个将(id)发件人作为textfield对象的快速方法。“从textfield移动”是什么意思?