繁体   English   中英

内置表格视图的UITableViewController和UIViewController之间切换

[英]Switching between UITableViewController and UIViewController with table view inside

我正在尝试从UITableViewController过渡到其中具有UITableView的UIViewController。

在我的HomeViewController中,我从

HomeViewController: UITableViewController 

HomeViewController: UIViewController, UITableViewDataSource, UITableViewDelegate

现在在情节提要中,当我将Table View拖到View Controller上时,TableView会自动调整为全屏大小...我在Controller中引用了tableView并设置了

tableView.delegate = self
tableView.datasource = self

但是在HomeViewController中,当我打印(self.view是UITableView)时,它会打印true。 当我尝试从情节提要中的HomeVC删除TableView并添加UIView时,它不会让我使用。 我很困惑为什么? 如何在UIViewController中从TableView过渡到TableView。 谢谢!

UITableViewController是的子类UIViewController ,在你strorybord已建成UITableViewController ,它管理UITableView和自定义类应的子类UITableViewController 因此您对自定义类对UIViewController的子类所做的更改将无法按预期工作。

您需要拖动UIViewController然后将UITableView添加为任何视图。 然后将自定义类设置为您拥有的类。

另外:.h

@interface HomeViewController : UIViewController 
//...
@end

.m

@interface HomeViewController ()<UITableViewDataSource,UITableViewDelegate> //implement Protocol
//...
@end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM