我有一个奇怪的问题。
我正在继承 UIViewController 并添加一个 tableView 属性,我在其中加载一个 UITableView。现在我将此 UITableView 添加到父级的子视图中。工作正常,但我得到两个TableViews。一种标准样式的 TableView 和一种我希望它位于标准样式之上的方式。两者都包含正确的数据。
@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);
设置框架没有任何影响......