2015-07-09 99 views
0

我似乎无法找到可用于将单元格添加到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; 
} 
+2

的代码放在您的自定义表v在控制器类中实现各种'UITableViewDataSource'方法。 – rmaddy

回答

0

如果您使用的是Xcode中提供tableViewController模板有

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 

- 在每一节

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 

中的行数的tableView节你在哪里n各自细胞

I'ld而是建议你应该看看一些基本教程appcode tutorial

0

请尝试以下的

代码编写的设置文本

- (UITableViewCell的*)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 

if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; 
} 
cell.textLabel.text = @"Test"; 
[cell.imageView setImage:[UIImage imageNamed:@"test.png"]]; 
cell.textLabel.font = [UIFont systemFontOfSize:16.0]; 
return cell; 

而且你可以添加自定义视图上面的代码

相关问题