文中代码粘贴复制自苹果UITableView的Recipes范例:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 4;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSString *title = nil;
// Return a title or nil as appropriate for the section.
switch (section) {
case TYPE_SECTION:
title = @"Category";
break;
case INGREDIENTS_SECTION:
title = @"Ingredients";
break;
default:
break;
}
return title;;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger rows = 0;
/*
The number of rows depends on the section.
In the case of ingredients, if editing, add a row in editing mode to present an "Add Ingredient" cell.
*/
switch (section) {