添加“详细信息视图"到 UITableView [英] Add "details view" to UITableView

查看:32
本文介绍了添加“详细信息视图"到 UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有多个视图控制器的 UITabbar.其中之一是 UITableView.tableview 存储在 nib 中,其中文件所有者是 UITableViewController.

I have a UITabbar with multiple view controllers. One of them is a UITableView. The tableview is stored in a nib where the file owner is a UITableViewController.

一旦选择了表格单元格,我希望表格视图显示详细信息视图"(带有 UILabel 和其他一些元素的自定义视图).我的方法是将新的详细信息视图作为子视图添加到 UITableView:

I'd like the tableview to show a "detail view" (custom view with a UILabel and some other elements) once a table cell is selected. My approach was to add the new details view as a child view to the UITableView:

[self.view addSubView:[detailsViewController view]]

不幸的是,这并没有产生我想要的效果.作为 UITableView 的子视图,我可以滚动到添加的详细信息视图之外并查看底层表条目.UINavigationBar 是一个选项,但由于没有更深的层次结构,我更喜欢带有关闭按钮的简单自定义视图.有什么建议吗?

Unfortunately that doesn't create the effect I want. As a subview of the UITableView, I can scroll beyond the added details view and see the underlying table entries. UINavigationBar is an option, but since there's no deeper hierarchy, I'd prefer a simple custom view with a close button. Any suggestions?

推荐答案

用 UIViewController 替换你的 UITableViewController.然后将 UITableView 添加到您的视图控制器.将表视图的委托和数据源设置为视图控制器.现在你可以在非滚动视图控制器中添加一个子视图,仍然有你的 tableview :)

Replace your UITableViewController with a UIViewController. Then add a UITableView to your view controller. Set the delegate and datasource of your table view to your view controller. Now you can add a subview in a non-scrolling view-controller, still having your tableview :).

或者,您可以在弹出视图出现时阻止 tableview 滚动.

Or, you can stop the tableview from scrolling when the popupview appears.

[(UIScrollView *)self.view setScrollEnabled:NO];
CGRect rect = self.popupview.frame;
rect.origin.y = [(UIScrollView *)self.view contentOffset].y;
self.popupview.frame = rect;

这篇关于添加“详细信息视图"到 UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆