繁体   English   中英

以编程方式加载UITableViewController并将视图添加为子视图

[英]Load UITableViewController programmatically and add view as subview

我想在UIView中加载UITableViewController,因为我想在单击按钮时更改视图(如UITabBar,但有我自己的按钮)。 我正在使用情节提要,并使用自定义类“ InitialTableViewController”和标识符“ InitialView”定义了TableViewController。

我的代码如下所示:

#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

视图开始,我可以看到我的表,但是“ InitialTableViewController”中的代码不起作用。

我能做什么?

好吧,只需要一个普通的UIViewController并将UIView作为Nib的根,然后放置一个UITableView会更容易。 我的答案是基于您需要在该UIView上具有按钮。

暂无
暂无

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

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