为什么在嵌入UINavigationController时不再显示UITableView

时间:2015-03-31 08:20:37

标签: ios uitableview swift uinavigationcontroller

我是iOS开发的新手。我现在正在学习斯威夫特。我目前有一个问题,我添加导航视图控制器后,我的tableView不再显示任何内容。我不明白为什么。请帮帮我专家!!

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.

    let mainVC = ViewController()
    let navigationVC = UINavigationController(rootViewController: mainVC)
    window?.rootViewController = navigationVC;
    window?.makeKeyAndVisible()
    return true
}

ViewController中的代码:

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var myTable: UITableView!
var items: [String] = ["Date Picker","List of Data","Slider","Show Image", "Web Display"];

override func viewDidLoad() {
    super.viewDidLoad()

    NSLog("Hello World at console");
    var nib = UINib(nibName: "ListCell", bundle: nil)
    myTable?.registerNib(nib, forCellReuseIdentifier: "ListCell")
    // Do any additional setup after loading the view, typically from a nib.
}

1 个答案:

答案 0 :(得分:0)

如果您正在使用storyboard,请使用其实例化方法,并在storyboard中设置控制器的storyboardID

YourController *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"ControllerStoryboardId"];

如果是xib文件

YourController *vc = [[YourController alloc] initWithNibName:@"YourController" bundle:[NSBundle mainBundle]];