0

私のアプリケーションは、作成したクラスTaskController : UINavigationController のルート ビュー コントローラーとして呼び出されるルート コントローラーから始まります(ビューとして追加されます)。アプリケーションを起動すると、TaskRootController からのタイトルと背景色のみが表示されます。しかし、テーブルビューが表示されません。アプリケーションがas で始まる場合、テーブル ビューが表示されます。UINavigationControllerTaskRootController : UIViewController<UITableViewDelegate>UITableViewTaskRootControllerrootViewController

場合によってはテーブルビューを表示するにはどうすればよいですか?

編集

 @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
4

2 に答える 2

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.
}
于 2013-03-20T05:03:58.903 に答える
0

@iPatel - TaskRootController をアプリでルートコントローラーとして設定すると ( UINavigationController のルートではなく)、すべて正常に表示されるため、これらのメソッドは単純なテーブルビュー (白い背景に灰色の点線) を表示する必要はないと思います。

@Manohar - 手の届くところにコードがありません。しかし、私が思い出したように、それは次のようになります。

self.taskRoot = [[TaskController alloc] initWithNill.....] //initialization of controller
self.window.rootViewController = self.taskRoot; 
[self.window makeKeyAndVisible];
于 2013-03-20T13:27:53.303 に答える