将 UITextView 放置在 UITableView 页脚内

发布于 2024-08-07 12:08:17 字数 917 浏览 3 评论 0原文

我有一个带有页脚视图的 UITableView。此页脚视图包含 UITextView 作为子视图。表格视图和页脚视图都是以编程方式创建的。文本视图正确显示在屏幕上,但它不显示任何文本,也不响应触摸事件。

问题是否与 UITextView 是 UIScrollView 的子类有关?或者我在文本视图的初始化中错过了一些东西?

我初始化页脚和文本视图的代码如下所示:

// Create the footer
UIView *tempFooter = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
[tempFooter setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
[tempFooter setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
self.tableFooterView = tempFooter;
[tempFooter release];

UITextView *tempTextView = [[UITextView alloc] initWithFrame:CGRectMake(5, 5, 270, 140)];
[tempTextView setDelegate:self];
[tempTextView setEditable:YES];
tempTextView.keyboardType = UIKeyboardTypeDefault;
tempTextView.returnKeyType = UIReturnKeyDone;
self.textView = tempTextView;
[tempTextView release];

[self.tableFooterView addSubView:self.textView];

I have a UITableView with footer view. This footer view contains a UITextView as a subview. Both the table view and footer view are created programmatically. The text view appears on screen correctly, but it doesn't display any text, nor does it respond to touch events.

Could the problem be related to the fact that UITextView is a subclass of UIScrollView? Or have I just missed something in my initialization of the text view?

The code where i initialize the footer and text view looks like this:

// Create the footer
UIView *tempFooter = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
[tempFooter setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
[tempFooter setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
self.tableFooterView = tempFooter;
[tempFooter release];

UITextView *tempTextView = [[UITextView alloc] initWithFrame:CGRectMake(5, 5, 270, 140)];
[tempTextView setDelegate:self];
[tempTextView setEditable:YES];
tempTextView.keyboardType = UIKeyboardTypeDefault;
tempTextView.returnKeyType = UIReturnKeyDone;
self.textView = tempTextView;
[tempTextView release];

[self.tableFooterView addSubView:self.textView];

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

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

发布评论

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

评论(1

残龙傲雪 2024-08-14 12:08:17

我最近遇到了类似的问题,发现某些输入元素的 superview (UIScrollView)的 contentSize 太小。将显示内容(clipsToBounds = NO),但不会检测到触摸。

您是否检查过您的实际表格是否足够高以容纳其页脚视图?

I bumped into a similar problem lately and discovered that the contentSize of the superview (A UIScrollView) of some input elements was too small. Content would display (clipsToBounds = NO), but touches would not be detected.

Did you check whether your actual table is high enough to also accomodate its footer view?

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