我似乎無法找到可用於將單元格添加到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