我如何连接UITableView到我的Appdelegate.m?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { MainViewController *rootViewController = [[MainViewController alloc] init]; _naviControl = [[UINavigationController alloc]initWithRootViewController:rootViewController]; self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; [self.window addSubview:_naviControl.view]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; } 

在我的AppDelegate ..! 连接到MainViewController.m

AppDelegate不是一个UIViewController,所以连接一个UITableView到它与MVC原则冲突,如下所述: https : //developer.apple.com/library/ios/documentation/general/conceptual/devpedia-cocoacore/MVC.html

你想要做的是让你的MainViewController的视图有一个tableView作为子视图

像这样:(在MainViewController.m)

 - (void)viewDidLoad { [super viewDidLoad]; self.feedTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; self.feedTableView.dataSource = self; self.feedTableView.delegate = self; [self.view addSubview:self.feedTableView]; }