IOS development and learning # Table view # (4) Filling Grouped-style grouping tables
Buy on your behalf directly:
@ Implementation ViewController-(void) viewDidLoad {a = [NSArray arrayWithObjects: @ "ant", @ "alpaca", @ "albatross", nil]; B = [NSArray arrayWithObjects: @ "badger", @ "bat", @ "bear", nil]; c = [NSArray arrayWithObjects: @ "cat", @ "calf", @ "cattle ", nil]; d = [NSArray arrayWithObjects: @ "A", @ "B", @ "C", nil]; [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib .} // set the number of rows in the table view-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {return 3;}-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {static NSString * CellIdentifier = @ "Cell"; UITableViewCell * cell = [tableView failed: CellIdentifier]; if (cell = nil) {cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier: CellIdentifier];} if (indexPath. section = 0) {cell. textLabel. text = [a objectAtIndex: indexPath. row];} if (indexPath. section = 1) {cell. textLabel. text = [B objectAtIndex: indexPath. row];} if (indexPath. section = 2) {cell. textLabel. text = [c objectAtIndex: indexPath. row];} return cell;} // set the number of nodes in the table view-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView {return [d count];} // get the section name-(NSString *) tableView :( UITableView *) tableView titleForHeaderInSection :( NSInteger) section {return [d objectAtIndex: section];}