2011-08-09 6 views
0

ここに私が使用したコードがあります。私は何が欠けていますか?トップにナビゲーションバーを持つテーブルビューを作成しようとしています

- (void)loadView 
{ 
    CGSize screen_size = [[UIScreen mainScreen] bounds].size; 

    CGFloat navBarHeight = 40; 

    UINavigationBar *nav = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, screen_size.width, navBarHeight)]; 

    UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(0, navBarHeight, screen_size.width, screen_size.height - navBarHeight) style:UITableViewStylePlain]; 

    table.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth; 
    table.delegate = self; 
    table.dataSource = self; 
    table.editing = YES; 
    [table reloadData]; 

    [self.view addSubview:nav]; 
    [self.view addSubview:table]; 
    [nav release]; 
    [table release]; 
} 

下にテーブルがあるナビゲーションバーの代わりに、ステータスバーの下に黒い画面が表示されます。

答えて

2

あなたのloadViewメソッドに含むビューを作成し、ビューコントローラのビューとして設定する必要があります:あなたはあなたのビューコントローラに関連付けられているのnibファイルを持っている場合は、あなたがすべき、

- (void)loadView { 


    CGSize screen_size = [[UIScreen mainScreen] bounds].size; 

    UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0,0,screen_size.width,screen_size.height)]; 
    self.view = myView; 

    CGFloat navBarHeight = 40; 

    UINavigationBar *nav = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, screen_size.width, navBarHeight)]; 

    UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(0, navBarHeight, screen_size.width, screen_size.height - navBarHeight) style:UITableViewStylePlain]; 

    table.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth; 
    table.delegate = self; 
    table.dataSource = self; 
    table.editing = YES; 
    [table reloadData]; 

    [self.view addSubview:nav]; 
    [self.view addSubview:table]; 
    [nav release]; 
    [table release]; 
    [myView release]; 

} 

または交互にloadViewではなくviewDidLoadメソッドを使用してください。

関連する問題