0

次のように、ビューコントローラー内に UITableView コントローラーをセットアップしました。

fieldView = [[UITableView alloc] initWithFrame:CGRectMake(0, logoView.bounds.size.height, 320, (screen.size.height - logoView.bounds.size.height)) style:UITableViewStylePlain];
[fieldView setBackgroundColor:[UIColor greenColor]];
fieldView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleTopMargin;

View Controller は、次のように TableViewDelegate になるように設定されています。

 UIViewController <UITableViewDelegate, UITableViewDataSource...

質問: この追加されたサブ ビューを制御するために、テーブル ビュー デリゲート メソッドに対して何をする必要がありますか?

#pragma mark - 
#pragma Table View Delegate Methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    NSLog(@"Here");
    return 1;
}
- (NSString *)tableView:(UITableView *)fieldView titleForHeaderInSection:(NSInteger)section {
    NSString *sectionName;
    NSLog(@"Here2");

上記のメソッドはView Controllerにありますが、呼び出されていませんか?

4

2 に答える 2

5

必要なもの:

// Add these right after creating the UITableView
fieldView.delegate = self;
fieldView.dataSource = self;

// don't forget to add the tableview
[self.view addSubview:fieldView];

また、すべての基本的な方法UITableViewDelegateUITableViewDataSource方法が必要です。を実装した場合とまったく同じですUITableViewController。少なくとも必要なもの:

tableView:numberOfRowsInSection:
tableView:cellForRowAtIndexPath:

テーブル編集をサポートする予定の場合は、実装してオーバーライドする必要のある追加のメソッドがあります。

于 2013-02-18T17:58:34.670 に答える
0

テーブル ビューのデリゲートとデータ ソースを設定する必要があります。

fieldView.delegate = controller; // self, if you are creating this table inside your controller
于 2013-02-18T17:59:06.760 に答える