Reputation: 95
I have a menu that opens from the left side of the screen when the menu opens, a dynamic generated menu cells appear on the screen. Can I add two static cells to it such as login and settings, all the way at the bottom?
Upvotes: 0
Views: 30
Reputation: 12260
When you implement table view data source, you can return number of dynamic cells + number of predefined cells.
cellForRowAtIndexPath:
in this case should handle this and depending on NSIndexPath
return an appropriate cell.
Assuming that last two cells of table view should be login and settings it's pretty straightforward how to implement a data source, for example:
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return NumberOfDynamicCells + 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == NumberOfDynamicCells) {
LoginCellView* cell = [tableView dequeueReusableCellWithIdentifier:@"LoginCell" forIndexPath:indexPath];
cell.titleLabel.text = @"Log in";
return cell;
} else if(indexPath.row == NumberOfDynamicCells + 1) {
SettingsCell* cell = [tableView dequeueReusableCellWithIdentifier:@"SettingsCell" forIndexPath:indexPath];
cell.titleLabel.text = @"Settings";
return cell;
} else {
DynamicCell* cell = [tableView dequeueReusableCellWithIdentifier:@"DynamicCell" forIndexPath:indexPath];
return cell;
}
}
Upvotes: 1