[英]Load UITableViewController programmatically and add view as subview
I want to load a UITableViewController inside a UIView because I want to change the view on button click (like UITabBar but with my own buttons). 我想在UIView中加载UITableViewController,因为我想在单击按钮时更改视图(如UITabBar,但有我自己的按钮)。 I'm using a storyboard and have defined a TableViewController with custom class "InitialTableViewController" and identifier "InitialView". 我正在使用情节提要,并使用自定义类“ InitialTableViewController”和标识符“ InitialView”定义了TableViewController。
My code look like this: 我的代码如下所示:
#import "MyViewController.h"
#import "InitialTableViewController.h"
@interface MyViewController ()
@end
@implementation MyViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
InitialTableViewController *tableControl = [self.storyboard instantiateViewControllerWithIdentifier:@"InitialView"];
[[self view] addSubview:[tableControl view]];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
@end
The view starts and I can see my table but the code inside "InitialTableViewController" doesn't work. 视图开始,我可以看到我的表,但是“ InitialTableViewController”中的代码不起作用。
What can I do? 我能做什么?
Well, it would be easier to just have a normal UIViewController
with a UIView
as root of the Nib and then put a UITableView
. 好吧,只需要一个普通的UIViewController
并将UIView
作为Nib的根,然后放置一个UITableView
会更容易。 My answer is based on your need to have buttons on that UIView
. 我的答案是基于您需要在该UIView
上具有按钮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.