iPhone SDK - UITableCell 的 UITextField 子视图出现绘图问题?

发布于 2024-08-22 07:09:39 字数 1065 浏览 2 评论 0原文

我将一些 UITextFields、UITextViews 和 UIImageViews 作为子视图添加到 UITableCell。当我在 TextFields 或 TextViews 中输入一些文本并向上或向下滚动表格时,我遇到了一些绘图问题。每隔一个字段的文本与其他字段重叠,如下所示:

替代文字

我正在创建这样的表单元素:

    self.formFields = [[NSArray alloc] initWithObjects:
[[UITextField alloc] initWithFrame:CGRectMake(18.0, 10.0, 284.0, 22.0)],
[[UITextView alloc] initWithFrame:CGRectMake(18.0, 8.0, 284.0, 140.0)],
[[UITextField alloc] initWithFrame:CGRectMake(18.0, 10.0, 284.0, 22.0)],
[[UITextField alloc] initWithFrame:CGRectMake(18.0, 10.0, 284.0, 22.0)],
[[UIImageView alloc] initWithFrame:CGRectMake(18.0, 18.0, 284.0, 284.0)],nil];

并添加子视图:

- (UITableViewCell *)tableView:(UITableView *)tableView
                         cellForRowAtIndexPath:(NSIndexPath *)indexPath {

      ...
     [cell addSubview:[self.formFields objectAtIndex:indexPath.section]];
     return cell;
}

有什么方法可以解决这个问题吗?

I'm adding some UITextFields, UITextViews and UIImageViews as subviews to a UITableCell. When I'm entering some text to the TextFields or TextViews and scroll the table up or down, I get some drawing issues. The text of every second field overlaps other fields like this:

alt text

I'm creating the form elements like this:

    self.formFields = [[NSArray alloc] initWithObjects:
[[UITextField alloc] initWithFrame:CGRectMake(18.0, 10.0, 284.0, 22.0)],
[[UITextView alloc] initWithFrame:CGRectMake(18.0, 8.0, 284.0, 140.0)],
[[UITextField alloc] initWithFrame:CGRectMake(18.0, 10.0, 284.0, 22.0)],
[[UITextField alloc] initWithFrame:CGRectMake(18.0, 10.0, 284.0, 22.0)],
[[UIImageView alloc] initWithFrame:CGRectMake(18.0, 18.0, 284.0, 284.0)],nil];

And adding the subview:

- (UITableViewCell *)tableView:(UITableView *)tableView
                         cellForRowAtIndexPath:(NSIndexPath *)indexPath {

      ...
     [cell addSubview:[self.formFields objectAtIndex:indexPath.section]];
     return cell;
}

Is there any way to fix this?

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

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

发布评论

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

评论(1

川水往事 2024-08-29 07:09:39

您是否在任何地方删除子视图?如果没有,它们就会不断添加到单元中并出现在彼此的顶部,因为单元正在被重用。要么在添加新子视图之前删除所有旧子视图,要么(这对我来说更符合逻辑)为每个部分创建不同的单元格标识符和单元格,然后在创建每个单元格时创建并添加适当的子视图。

Are you removing the subviews anywhere? If not, they just keep getting added to the cell and appear on top of each other because the cell is being reused. Either remove any old subviews before adding a new one or (this is more logical to me) create different cell identifiers and cells for each section, then create and add the appropriate subview when you create each cell.

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