奇妙な問題があります。
UIViewController をサブクラス化し、UITableView をロードする tableView プロパティを追加しています。今、この UITableView を親のサブビューに追加しています。正常に動作しますが、2 つの TableView が表示されます。1 つは標準スタイルの TableView で、もう 1 つは標準スタイルの上に配置したい方法です。ただし、どちらにも正しいデータが含まれています。
@interface RootViewController : UIViewController <ABPersonViewControllerDelegate, UITableViewDelegate, UITableViewDataSource> {
UITableView *tableView;
ToolbarController *toolbar;
...
}
@property(nonatomic, retain) UITableView *tableView;
@property(nonatomic, retain) ToolbarController *toolbar;
...
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
CGRect mainViewBounds = self.parentViewController.view.bounds;
CGFloat toolbarHeight = 44;
toolbar = [[ToolbarController alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(mainViewBounds), toolbarHeight) parentView:self];
tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, toolbarHeight, CGRectGetWidth(mainViewBounds), CGRectGetHeight(mainViewBounds) - toolbarHeight) style:UITableViewStylePlain];
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
tableView.rowHeight = 60.0;
[tableView tableView].delegate = self;
[tableView tableView].dataSource = self;
tableView.backgroundColor = [UIColor clearColor];
[self.parentViewController.view addSubview:tableView];
[self.parentViewController.view addSubview:toolbar];
}
@end
- - - 更新しました - - -
一部だけ貼り間違えました
[tableView tableView].delegate = self;
[tableView tableView].dataSource = self;
実際にはコードにあります
tableView.delegate = self;
tableView.dataSource = self;
-------更新2--------
独自の UITableView を作成しない場合
tableView = [[UITableView alloc] ...]
次に、自動的に設定されたものがあります。これは私にとっては問題ありません...初期化する必要はありませんが、標準のフレームを変更することはできません。
tableView.frame = CGRectMake(0, toolbarHeight, CGRectGetWidth(mainViewBounds), CGRectGetHeight(mainViewBounds) - toolbarHeight);
フレームを設定しても何の効果もありません...