iPhone 上不显示键盘

发布于 2024-12-05 02:01:12 字数 2573 浏览 1 评论 0原文

我已向表视图中的某些行添加了一个 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 中的文本,键盘不会出现。为什么?

I have added to some rows from table view an TextField like this :

  - (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;
}

The problem is that the keyboard doesn't appear if I want to change the text from TextField. Why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

策马西风 2024-12-12 02:01:12

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

Most probably there is something in the way of the text field and that makes it not receiving the touch event. Adding the entire cellForRowAtIndexPath would probably help us understand better what's happenning. Also, you should add the texfield and other custom elements to cell.contentsView, not directly to the cell.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文