简体   繁体   English

UITableView作为AppDelegate中的子视图

[英]UITableView as subview in AppDelegate

After surprisingly the world didn't end today I continue coding, 令人惊讶的是世界并没有今天结束后,我继续编码,

I made UITableViewController, it works very good when using segue, but I want to make this controller subview in AppDelegete (to make side menu like facebook). 我制作了UITableViewController,在使用segue时效果很好,但是我想在AppDelegete中制作该控制器的子视图(以制作侧面菜单,例如facebook)。

So I my AppDelegate (didFinishLaunchingWithOptions) I added this: 所以我在我的AppDelegate(didFinishLaunchingWithOptions)中添加了以下内容:

UIStoryboard* sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

SideMenuViewController * rm = (SideMenuViewController *)[sb instantiateViewControllerWithIdentifier:@"RightMenu"];

[self.window addSubview:rm.tableView];

it adds the table and the table renders correctly, until I click on some cell or try to scroll, and suddenly everything in this table disappears, I see compltely empty table, no section and no cells. 它会添加表格,表格会正确呈现, 直到我单击某个单元格或尝试滚动,然后该表格中的所有内容突然消失,我看到的是完全空的表格,无节且无单元格。

What can I do? 我能做什么? It may be some delegate issues because it's instantiated in the AppDelegate? 可能是一些委托问题,因为它是在AppDelegate中实例化的?

Thanks a lot! 非常感谢!

You must set a rootViewControlle r property of the window . 您必须设置windowrootViewControlle r属性。 May be this will help..any way insert this code between adding the table as subview and controller instantiation: 可能会有所帮助。.以任何方式在将表添加为子视图和控制器实例化之间插入以下代码:

self.window.rootViewController = rm;

I have no experience whatsoever with storyboards, so this is a wild guess: Is the SideMenuViewController instance being deallocated after it is used to populate the initial table view? 我对故事板没有任何经验,因此这是一个疯狂的猜测:在将SideMenuViewController实例用于填充初始表视图之后,是否将其释放? The UIStoryboard object sure seems to be non-retained, but I am not sure about the controller returned by instantiateViewControllerWithIdentifier: . UIStoryboard对象肯定似乎未被保留,但是我不确定由instantiateViewControllerWithIdentifier:返回的控制器。

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

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