@implementation CustomTableViewController
- (void)viewDidLoad
{
[self.navigationController.navigationBar setTranslucent:NO];
[super viewDidLoad];
[self addTableView];
[self loadData];
[self addToolbar];
}
- (void)addTableView
{
self.tableView = [[UITableView alloc] init];
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.tableView.backgroundColor = [UIColor whiteColor];
self.tableView.frame = self.view.frame;
self.tableView.autoresizingMask = self.view.autoresizingMask;
[self.view addSubview:self.tableView];
}
- (void)loadData
{
self.data = [NSMutableArray array];
for (int i = 0; i<20; i++)
{
[self.data addObject:[NSString stringWithFormat:@"Row %d", i]];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.textLabel.text = [self.data objectAtIndex:indexPath.row];
cell.textLabel.textColor = [UIColor redColor];
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.data.count;
}
- (void)addToolbar
{
self.toolBar = [[UIView alloc] init];
self.toolBar.backgroundColor = [UIColor greenColor];
[self.view addSubview:self.toolBar];
[self resize];
}
- (void)resize
{
float height = 50;
self.toolBar.frame = CGRectMake(
0,
self.view.frame.size.height - height,
self.view.frame.size.width,
height
);
self.tableView.frame = CGRectMake(
0,
0,
self.view.frame.size.width,
self.view.frame.size.height-height
);
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[self resize];
}
self.tableView.tableFooterView = self.toolbar;
|----------------------------|
| |
| |
| |
| tableView |
| |
| |
|----------------------------|
|----------------------------|
| ToolBarView. |
|----------------------------|