键盘没有出现在Iphone上

时间:2011-09-19 09:15:23

标签: iphone keyboard textfield

我在表格视图中添加了一些像这样的TextField:

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {

        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
        // cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        // cell.accessoryType = UITableViewCellAccessoryNone;

        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        cell.backgroundView.opaque = NO;
        //cell.alpha = 0.65;

        cell.textLabel.backgroundColor = [UIColor clearColor];
        cell.textLabel.opaque = NO;
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.textLabel.highlightedTextColor = [UIColor whiteColor];
        cell.textLabel.font = [UIFont boldSystemFontOfSize:18];

        cell.detailTextLabel.backgroundColor = [UIColor clearColor];
        cell.detailTextLabel.opaque = NO;
        cell.detailTextLabel.textColor = [UIColor whiteColor];
        cell.detailTextLabel.highlightedTextColor = [UIColor whiteColor];
        cell.detailTextLabel.font = [UIFont systemFontOfSize:14];

        if(indexPath.row==1)
        {
            code=[[UITextField alloc] init];
            code.frame = CGRectMake(200,10,80,50);
            code.textColor=[UIColor grayColor];
            code.text=@"515800";
            [cell.contentView addSubview:code];

        }
        if(indexPath.row==2)
        {
            ville=[[UITextField alloc] init];
            ville.frame = CGRectMake(200,10,80,50);
            ville.textColor=[UIColor grayColor];
            ville.text=@"Paris";
            [cell.contentView addSubview:ville];

        }
        if(indexPath.row==4)
        {
            nomdepartenaire=[[UITextField alloc] init];
            nomdepartenaire.frame = CGRectMake(200,10,80,50);
            nomdepartenaire.textColor=[UIColor grayColor];
            nomdepartenaire.text=@"Alliantis Ttttt";
            [cell.contentView addSubview:nomdepartenaire];

        }
    }

    // Set up the cell...
    [[cell textLabel] setText: [listData objectAtIndex:indexPath.row]] ;

    return cell;
}

问题是如果我想从TextField更改文本,则不会出现键盘。为什么呢?

1 个答案:

答案 0 :(得分:0)

最有可能的是文本字段的方式,并使其无法接收触摸事件。添加整个cellForRowAtIndexPath可能有助于我们更好地理解发生了什么。此外,您应该将texfield和其他自定义元素添加到cell.contentsView,而不是直接添加到单元格。