【问题标题】:Load UITableViewController programmatically and add view as subview以编程方式加载 UITableViewController 并将视图添加为子视图
【发布时间】:2012-05-07 17:25:11
【问题描述】:

我想在 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”中的代码不起作用。

我能做什么?

【问题讨论】:

  • 我认为您需要在某处保留tableControl 实例。在 MyViewController 上有一个属性,并在 viewDidLoad 中创建它后设置值。

标签: ios uitableview uistoryboard


【解决方案1】:

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

【讨论】:

  • 非常感谢。如何添加导航控制器以在我的故事板中使用 seque?
  • 我找到了一个解决方案,在 UIViewController 前面添加了一个 UINavigationController。
猜你喜欢
  • 1970-01-01
  • 2011-08-22
  • 1970-01-01
  • 2017-01-12
  • 2016-07-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多