UITableView未滚动时未分配给父级UIViewController视图属性 [英] UITableView not scrolling when not assigned to parents UIViewController view property

查看:81
本文介绍了UITableView未滚动时未分配给父级UIViewController视图属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我把一个UITableView放在一个UIViewController内,并从UITableViewController复制代码到我的UIViewController,让它实现表数据协议与UITableViewControllers默认实现和下面 http://developer.apple.com /library/IOs/#documentation/UserExperience/Conceptual/TableView_iPhone/CreateConfigureTableView/CreateConfigureTableView.html#//apple_ref/doc/uid/TP40007451-CH6-SW10 的以编程方式创建表视图一章(使用ViewDidLoad而不是LoadView,因为我使用IB和有一个nib,我为名为tableView的UITableView创建了一个插座。)



现在在上面的链接章节UITableView被分配给自我。视图是UIViewController的UIView属性。然后滚动UITableView是工作,但UITableView填充整个屏幕隐藏其他视图内容,如UIToolbar - 可能是因为它是分配给视图属性后的唯一内容。



如果我省略了分配,其他视图内容就位,一切都大小正确,但UITableView不滚动。



如何实现滚动



这里是相关的代码:

  //实现viewDidLoad在加载视图之后执行额外的设置,通常来自nib。 
- (void)viewDidLoad
{
[super viewDidLoad];
tableView.delegate = self;
tableView.dataSource = self;
[tableView reloadData];
//self.view = tableView;
}


解决方案

您在接口构建器中添加的视图控制器,这将是UIViewController的.view属性的一部分 - 当您将表视图分配给此视图时,将删除所有内容。



如果您的表视图正常显示,但没有滚动(如何选择?这是否有效?)您可能已禁用用户交互。



您在评论中提到在您的表格视图中只有空单元格 - 我认为这是您的问题的原因。我刚刚创建了一个示例项目,其中我已经在表视图中添加了视图控制器的视图的子视图,滚动很好 - 这是我填充了100个虚拟行。如果我不为数据源和委托方法返回任何东西,那么表视图不会滚动。


I have put an UITableView inside a UIViewController and have copied code from UITableViewController over to my UIViewController to have it fulfill "Table data protocols" with UITableViewControllers default implementation and am following http://developer.apple.com/library/IOs/#documentation/UserExperience/Conceptual/TableView_iPhone/CreateConfigureTableView/CreateConfigureTableView.html#//apple_ref/doc/uid/TP40007451-CH6-SW10s chapter "Creating a Table View Programmatically" (with using ViewDidLoad instead of LoadView as I use IB and have a nib, I created an outlet for the UITableView named tableView).

Now in above links chapter the UITableView is assigned to self.view which is the UIView property of the UIViewController. Then scrolling the UITableView is working but the UITableView fills the entire screen hiding other view content such as an UIToolbar - probably as it is the sole content after being assigned to the view property.

If I omit the assignment, the other view content is in place an everything is sized properly, however the UITableView doesn't scroll.

How do I achieve scrolling of the UITableView inside an UIViewController with the UIVC having static content (such as a toolbar)?

Here's the relevant code:

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
    tableView.delegate = self;
    tableView.dataSource = self;
    [tableView reloadData];
    //self.view = tableView;
}

解决方案

If you have other content in the view controller that you are adding in interface builder then this will be part of the UIViewController's .view property - when you assign the table view to this, you are removing all that content.

If your table view is appearing normally but is not scrolling (how about selection? Does that work?) you may have disabled user interaction on it.

You have mentioned in comments that there is nothing but empty cells in your table view - I think this is the cause of your problem. I have just created a sample project where I have added in a table view as a subview of the view controller's view, and scrolling is fine - this is with me populating 100 dummy rows in there. If I don't return anything for the datasource and delegate methods, then the table view does not scroll.

这篇关于UITableView未滚动时未分配给父级UIViewController视图属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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