【问题标题】:A UITextField in a UITableViewCellUITableViewCell 中的 UITextField
【发布时间】:2011-09-19 08:38:24
【问题描述】:

这几天我一直在尝试这样做,但无济于事。我也有点搞混了。现在我真的很困惑我应该如何处理这个问题。从哪里开始新的 .h 和 .m 文件。 :/

我的目标是在几个 UITableViewCell 中放置一个 UITextField。就像这样:

还有这个:

有人可以帮我做一些教程吗?

谢谢。

【问题讨论】:

    标签: iphone xcode uitableview uitextfield


    【解决方案1】:
        - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                           reuseIdentifier:kCellIdentifier] autorelease];
            cell.accessoryType = UITableViewCellAccessoryNone;
        }
            if (indexPath.row== 0) {
                UITextField *TextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
                TextField.adjustsFontSizeToFitWidth = YES;
                TextField.textColor = [UIColor blackColor];
                    TextField.placeholder = @"mathie";
                    [cell addSubview:TextField];
                }
    return cell;
    }
    

    【讨论】:

    • 您不应该调整文本字段的高度,使其填充单元格高度以便于选择吗?
    【解决方案2】:

    您可以创建一个由 UITableViewCell 组成的新 NIB。一旦你有了它,你可以添加任何其他 UI 元素,在你的情况下是 UITextField。

    在您的代码中,您可以像这样调用您的自定义 UITableViewCell:

    UITableViewCell *cell = [saleItemsTableView dequeueReusableCellWithIdentifier:cellIndedifier];
    
    if (cell == nil)
    {
        [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
        cell = saleItemsCell;
    }
    

    希望这会有所帮助。

    问候

    【讨论】:

    • 嗯...以编程方式绘制会更容易吗?我读过一些论坛说加载 nib 文件会减慢应用程序的速度?你知道如何画它们而不是触摸笔尖吗?谢谢。
    • 并非如此,如果您只想加载一些简单的 UITextField 对象,我真的看不出这会对性能产生什么重大影响。
    【解决方案3】:

    查看下面的苹果默认教程。

    对你有帮助。

    https://developer.apple.com/library/prerelease/ios/#samplecode/AdvancedTableViewCells/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009111

    这是关于“AdvancedTableViewCells”的。

    它会要求登录您的苹果帐户。所以只需登录并下载示例。

    【讨论】:

    • 抱歉,该教程没有演示 UITableViewCell 中的 UITextField。你知道还有其他类似于我发布的图片中显示的登录功能吗?谢谢。
    • 哦!好的。目前,我没有。如果有的话会告诉你。
    猜你喜欢
    • 1970-01-01
    • 2019-11-27
    • 2010-09-25
    • 2011-06-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多