簡體   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