开发者

Keyboard doesn't disappear

I added uitextfield programatically to uitableview cell, the problem is when I type on the textfield and click done or move from the textfield the keyboard doesn't disappear.

Any suggestion to solve that?

@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开发者_StackOverflow社区 = [[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


I think you're missing the following in textFieldShouldReturn:

[textField resignFirstResponder];

then your return YES;


try putting a NSNotification when keyboard is appeared and set the textfield as firstresponsder. The problem you are using might be because of the textfield is not the first responsder in your case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜