【问题标题】:editable UITextArea values in UITableViewUITableView 中可编辑的 UITextArea 值
【发布时间】:2011-05-24 16:24:57
【问题描述】:

我需要一个带有键和值的基本 UITableView。我修改每个单元格以包含一个 UILabel 和一个 UITextArea。我的问题是当我单击单元格时,单元格给出蓝色的点击响应,但键盘没有出现,并且 UITextField 没有显示任何编辑响应。

在 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 我可以获取 textField,并为其设置文本,但我想打开键盘在 textField 中写入。

当我修改单元格时,我将所有 UITextFields 设置为 firstResponder,但没有运气。

有人吗?

【问题讨论】:

    标签: iphone uitableview uitextfield


    【解决方案1】:

    据我所知,您可以使用 UITableViewStyleValue1 并将 detailTextlabel 设置为 CellForRow 中的 UITextlabel。但请注意 TextLabel 具有合适的宽度和高度。然后您不必选择单元格,而是可以直接点击 UITextLabel

    【讨论】:

    • 感谢您的回复。你有这方面的参考吗?
    【解决方案2】:

    我查看了我的一个较旧的项目,发现我当时处理的事情有点不同。这是我所做的:

    cell = [self.aTableView dequeueReusableCellWithIdentifier:kPlaceCell];
                    if (cell == nil) {
                        cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleValue1 reuseIdentifier:kPlaceCell] autorelease];
                    }
    
    
    //PlaceField = An Instance of UITextfield, which I implemented as classvar.             
                   [self.placeField removeFromSuperview];
    
    // setting frame and font for your textfield. If you have static text in your Textlabel you should have an higher x so maybe CGRectMake (1, 100, 218, 39)
    
                    self.placeField.frame = CGRectMake(1, 1, 318, 39);
                    self.placeField.font = [UIFont boldSystemFontOfSize:18.0f];
    
    //Adding your UITextfield to the UITableViewCell contentView
    
                    [cell.contentView addSubview: self.placeField];
                }
    

    如果有人想知道:我使用了这个 tableView 以便用户可以创建一个用户帐户并使用占位符来表示(姓名、出生日期……),所以我不需要静态文本。 ^^

    告诉我这对你有什么作用,或者如果你需要进一步的解释

    【讨论】:

    • 谢谢!这是个好主意。我最终使用了 Apples CoreDataRecipes 示例项目中的 EditingTableViewCell,因为我没有测试你的代码。我会记住这一点,下次测试它!
    • 是的,使用 Apple 的示例代码和指南总是最好的主意,如果它适合你,那应该没问题 :-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-13
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    相关资源
    最近更新 更多