UITableViewCellStyleValue2 编辑文本 - 填充表单,如

发布于 2024-11-19 13:22:24 字数 251 浏览 4 评论 0原文

我需要创建一个表单,以便用户可以编辑表格的所有单元格(大约 20 个)。

我可以用 UITableViewCellStyleValue2 来做吗?如果是这样,怎么办?

或者我需要创建 UITableViewCell 的子类吗?

就 arquitect 而言,也许创建一个子类更好,但无论如何,我需要编辑表、textlabel.text 属性。

最好的办法是什么?我该怎么做呢?

谢谢,

RL

I need to create a form so that the user can edit all cells of the table (about 20).

Can I do it with UITableViewCellStyleValue2? If so, how?

Or do I need to create a subclass of UITableViewCell?

In terms of arquitect, maybe it's better to create a subclass, but anyway, i'll need to edit the table, the textlabel.text property.

What's the best way? And how can I do it?

Thanks,

RL

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

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

发布评论

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

评论(1

雪落纷纷 2024-11-26 13:22:24

我建议将您自己的视图添加到单元格的 contentView 中,如下所示:

- (UITableViewCell *)tableView:(UITableView *)tv
    cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    UITableViewCell *cell;
    {
        NSAutoreleasePool *arp = [[NSAutoreleasePool alloc] init];

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                reuseIdentifier:nil];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];

        UILabel *lbl = [[UILabel alloc] init];
        lbl.frame = CGRectMake(3, 2, 160, tv.rowHeight - 4);
        lbl.backgroundColor = [UIColor clearColor];
        lbl.textColor = [UIColor blackColor];
        lbl.font = [UIFont boldSystemFontOfSize:16];
        [cell.contentView addSubview:lbl];
        [lbl release];

        if(indexPath.row == 0)
        {
            lbl.text = @"Cell Name";

            UITextField *textField;
            textField = [[UITextField alloc] initWithFrame:CGRectMake(170,
                        tv.rowHeight / 2 - 10, 100, 20)];
            textField.borderStyle = UITextBorderStyleNone;
            textField.textColor = [UIColor blackColor];
            textField.font = [UIFont systemFontOfSize:14];
            textField.placeholder = @"Placeholder";
            textField.backgroundColor = [UIColor clearColor];
            textField.autocorrectionType = UITextAutocorrectionTypeNo;
            textField.keyboardType = UIKeyboardTypeDefault;
            textField.returnKeyType = UIReturnKeyDone;
            textField.tag = indexPath.row;
            textField.delegate = self;

            [cell.contentView addSubview:textField];
            [textField release];
        }

        ...

        [arp drain];
    }

    return [cell autorelease];
}

这只是一个演示,但您可以看到需要在哪里扩展它以支持其他单元格等。

I recommend adding your own views to the cell's contentView, like so:

- (UITableViewCell *)tableView:(UITableView *)tv
    cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    UITableViewCell *cell;
    {
        NSAutoreleasePool *arp = [[NSAutoreleasePool alloc] init];

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                reuseIdentifier:nil];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];

        UILabel *lbl = [[UILabel alloc] init];
        lbl.frame = CGRectMake(3, 2, 160, tv.rowHeight - 4);
        lbl.backgroundColor = [UIColor clearColor];
        lbl.textColor = [UIColor blackColor];
        lbl.font = [UIFont boldSystemFontOfSize:16];
        [cell.contentView addSubview:lbl];
        [lbl release];

        if(indexPath.row == 0)
        {
            lbl.text = @"Cell Name";

            UITextField *textField;
            textField = [[UITextField alloc] initWithFrame:CGRectMake(170,
                        tv.rowHeight / 2 - 10, 100, 20)];
            textField.borderStyle = UITextBorderStyleNone;
            textField.textColor = [UIColor blackColor];
            textField.font = [UIFont systemFontOfSize:14];
            textField.placeholder = @"Placeholder";
            textField.backgroundColor = [UIColor clearColor];
            textField.autocorrectionType = UITextAutocorrectionTypeNo;
            textField.keyboardType = UIKeyboardTypeDefault;
            textField.returnKeyType = UIReturnKeyDone;
            textField.tag = indexPath.row;
            textField.delegate = self;

            [cell.contentView addSubview:textField];
            [textField release];
        }

        ...

        [arp drain];
    }

    return [cell autorelease];
}

This is just a demonstration but you can see where you need to extend it to support additional cells, etc.

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