我似乎无法找到可用于将单元格添加到xcode中的表格而没有Storyboard(如果可能的话)的方法/代码行。这似乎是一个非常快速的解决方案,我只是没有找到它。 如果你知道这个例子,请指出。以编程方式向UITableViewController添加表格单元格
#import "AppDelegate.h"
#import "SubViewController.h"
#import "SubTableViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
//subviewcontroller = tabbarcontroller
UITabBarController * tabBarController = [[UITabBarController alloc] init];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SubViewController * firstTab= [[SubViewController alloc] init ];
[firstTab.view setBackgroundColor:[UIColor greenColor]];
firstTab.title = @"first";
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:firstTab];
SubViewController *secondTab = [[SubViewController alloc] init];
[secondTab.view setBackgroundColor:[UIColor redColor]];
secondTab.title = @"second";
UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:secondTab];
SubTableViewController * table = [[SubTableViewController alloc] init];
UINavigationController * nav3 = [[UINavigationController alloc]initWithRootViewController:table];
table.title = @"third";
tabBarController.viewControllers = @[navigationController1,navigationController2, nav3];
[self.window setRootViewController:tabBarController];
[self.window makeKeyAndVisible];
return YES;
}
的代码放在您的自定义表v在控制器类中实现各种'UITableViewDataSource'方法。 – rmaddy