2013-03-21 3 views
0

Мое приложение начинается с контроллера Root называется TaskController : UINavigationController и как вид корневой контроллер UINavigationController я создал класс TaskRootController : UIViewController<UITableViewDelegate> (он имеет вид добавить в UITableView); Когда я запускаю приложение, я вижу только название формы TaskRootController и цвет фона. Но я не вижу табличный вид. Если мое приложение запускается с TaskRootController как rootViewController, я вижу табличное представление.Не вижу UITableView

Как я могу сделать вид таблицы в случае, если? PS. Даже если я переключу TaskRootController на TaskRootController: UITableViewController - это то же самое. мой код ниже:

AppDelegate.m

@implementation AppDelegate 

@synthesize window = _window; 
@synthesize taskController; 

- (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]; 

    self.taskController = [TaskController alloc]; 
    self.window.rootViewController = self.taskController; 

    [self.window makeKeyAndVisible]; 
    return YES; 
} 

- (void)applicationWillResignActive:(UIApplication *)application 
{ 

} 

- (void)applicationDidEnterBackground:(UIApplication *)application 
{ 

} 

- (void)applicationWillEnterForeground:(UIApplication *)application 
{ 

} 

- (void)applicationDidBecomeActive:(UIApplication *)application 
{ 

} 

- (void)applicationWillTerminate:(UIApplication *)application 
{ 

} 

@end 

TaskController.m

@implementation TaskController 

@synthesize taskRootController; 

- (void) pushInboxController 
{ 
    TaskBoxController *taskBoxController = [[TaskBoxController alloc] initWithNibName:nil bundle:NULL]; 
    [self pushViewController:taskBoxController animated:YES]; 
} 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
     [self.navigationBar setBarStyle: UIBarStyleBlack]; 
     [self.navigationBar setTranslucent: NO]; 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
    self.taskRootController = [[TaskRootController alloc] initWithNibName:nil bundle:NULL]; 
    UIViewController *root = self.taskRootController; 
    [self initWithRootViewController: root]; 

} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear: animated]; 
    [self performSelector:@selector(pushInboxController)]; 
} 

@end 

TaskRootController.m

@implementation TaskRootController 

@synthesize taskRootView; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
    NSLog(@"DUPA"); 

    NSLog(@"SIZE x:%f,y:%f ; %f:%f", self.view.bounds.origin.x, self.view.bounds.origin.y, self.view.bounds.size.width, self.view.bounds.size.height); 
    self.view.backgroundColor = [UIColor grayColor]; 
    self.title = @"Root"; 
    self.taskRootView = [[UITableView alloc] initWithFrame: CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height) style:UITableViewStyleGrouped]; 
    self.taskRootView.delegate = self; 
    self.taskRootView.dataSource = self; 
    [self.view addSubview:self.taskRootView]; 

} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    // Return the number of sections. 
    return 1; // put number for section. 
} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of rows in the section. 
    return 6; // put number as you want row in section. 
} 

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    CGFloat result = 20.0f; 
    if([tableView isEqual:self.taskRootView]) 
    { 
     result = 40.0f; 
    } 
    return result; 
} 

@end 
+0

Почему вы берете острие имя как "ноль" в этом self.taskRootController = [[TaskRootController Alloc] initWithNibName: ноль расслоение: NULL]; –

+0

, потому что у меня нет xib-файла – lukisp

+0

, тогда попробуйте назначить taskController как this self.taskController = [[TaskController alloc] init]; вместо self.taskController = [TaskController alloc]; –

ответ

1

Добавить этот метод делегата.

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

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 
    cell.textLabel.text = @"this is row"; 

    return cell; 
} 

EDIT:

поставил init в том, когда вы создаете объект TaskController в AppDelegate.m

self.taskController = [[TaskController alloc]init]; 

А также поставил как делегат и источник данных для TaskController.h

<UITableViewDataSource, UITableViewDelegate> 

и добавьте его способы использования.

+0

Я добавляю этот метод в TaskRootController, который содержит вид таблицы и все еще ничего – lukisp

+0

@ lukisp- проверить мои отредактированные :) – iPatel

+0

Хорошо спасибо. Я не знаю, когда я пропущу это мнение: D – lukisp

0

В вашем AppDelegate

 self.taskController = [[TaskController alloc]initWithNibName:@"TaskController" bundle:[NSBundle mainBundle]]; 
    UINavigationController *task = [[UINavigationController alloc] initWithRootViewController:self.taskController]; 

    self.window.rootViewController = task; 

В вашей TaskController

- (void)viewDidLoad 
     { 
     [super viewDidLoad]; 
     TaskRootController *tc = [[TaskRootController alloc] initWithNibName:@"TaskRootController" bundle:[NSBundle mainbundle]]; 
     [self addChildViewController:tc]; 
     [tc didMoveToParentViewController:self]; 
     [self.view addSubview:tc.view]; 
     } 
0

Попробуйте ::

набор делегат и источник данные вашего Tableview

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return 50; 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    return [yourArray count]; 

} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
static NSString *MyIdentifier = @"MyIdentifier"; 

    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
    if (cell == nil){ 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease]; 
    } 
    cell.textLabel.text = @"row"; 
    return cell; 
} 

Надеется, что это поможет Эй у

0
in Appdelegate File :- 

self.TaskViewController = [[TaskViewController alloc] initWithNibName:@"TaskViewController" bundle:nil]; 
self.navigationController=[[UINavigationController alloc]initWithRootViewController:self.TaskViewController]; 

[self.window setRootViewController:navigationController];//ios-6 
          or 
[self.window addSubview:navigationController.view];//<ios-6 

Add a Delegate Method in UITableViewDelagates:- 

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

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 
    cell.textLabel.text = @"Name"; 

    return cell; 
} 
Смежные вопросы