2013-03-20 88 views
0

我的應用程序與稱爲TaskController : UINavigationController 作爲爲根視圖控制器UINavigationController根控制器開始,我創建TaskRootController : UIViewController<UITableViewDelegate>類(它已添加爲視圖UITableView); 當我啓動應用程序時,我只看到標題表單TaskRootController和它的背景顏色。 但我沒有看到表格視圖。 如果我的申請以TaskRootController作爲rootViewController開頭,我會看到表格視圖。視圖中不可見

我怎樣才能看到表格視圖在五月案?

編輯

@implementation TaskRootController 

@synthesize taskRootView; //table view 

- (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(@"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: self.view.bounds style:UITableViewStylePlain]; 
    [self.view addSubview:self.taskRootView]; 
    self.taskRootView.delegate = self; 
} 

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

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

@end 
+1

發佈您的代碼。如何設置rootViewController? – 2013-03-20 05:04:33

+0

@PratyushaTerli:返回+1! – 2013-03-20 05:05:17

+0

@Manohar謝謝 – 2013-03-20 05:06:01

回答

0

對於添加UITableView

放委託和數據源中TaskRootController.h文件。

@interface TaskRootController : UIViewController <UITableViewDataSource, UITableViewDelegate> 

,並把這個代碼在TaskRootController.m文件

self.tblView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height) style:UITableViewStyleGrouped]; 
    self.tblView.delegate = self; 
    self.tblView.dataSource = self; 
    [self.view addSubview:self.tblView]; 

並添加相關委託和數據源的UITabelView方法。

編輯:

檢查下面的方法..添加它正確與否?

- (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. 
} 
+0

我認爲這些方法不需要簡單的表格視圖(白色背景用灰色虛線),因爲TaskRootController可以延伸everythink當我在我的應用程序中將其設置爲根控制器時(不是我的UINavigationController中的根目錄) – lukisp 2013-03-20 07:30:57

0

@iPatel - 我認爲是不需要的那些方法,以顯示簡單的表視圖(白色背景,灰色點劃線),因TaskRootController顯示一切確定,當我在我的應用程序(未根在將其設置爲根控制器我的UINavigationController)

@Manohar - 我沒有代碼在手臂範圍內。但正如我記得它看起來像:

self.taskRoot = [[TaskController alloc] initWithNill.....] //initialization of controller 
self.window.rootViewController = self.taskRoot; 
[self.window makeKeyAndVisible];