# Import "viewcontroller. H "@ interface viewcontroller () @ property (strong, nonatomic) nsarray * BJ; @ property (strong, nonatomic) nsarray * Gd; @ end @ implementation viewcontroller-(void) viewdidload {[Super viewdidload]; self. bj = @ [@ "Dongcheng", @ "Xicheng", @ "Xuanwu", @ "Chongwen"]; self. GD = @ [@ "Guangdong", @ "Foshan", @ "Shenzhen"] ;}# data source method of Pragma mark-tableview # Number of Pragma mark groups-(nsinteger) numberofsectionsintableview :( uitableview *) tableview {re Turn 2 ;}# Pragma mark the number of tables displayed in each group, specifying the number of rows in each group-(nsinteger) tableview :( uitableview *) tableview numberofrowsinsection :( nsinteger) section {If (Section = 0) {return self. BJ. count;} else {return self. GD. count ;}# Pragma mark the data content displayed in each table. The data source is responsible for the content. // @ Interface nsindexpath (uitableview) // + (nsindexpath *) indexpathforrow :( nsinteger) Row insection :( nsinteger) Section; // @ property (nonatomic, readonly) nsinteger section; // @ property (nonatomic, readonly) nsinteger row; // @ end // you can use the current indexpath to determine the current row and group-(uitableviewcell *) tableview :( uitableview *) tableview cellforrowatindexpath :( nsindexpath *) indexpath {uitableviewcell * cell = [[uitableviewcell all OC] initwithstyle: uitableviewcellstyledefault reuseidentifier: Nil]; nsstring * cityname = nil; // group if (indexpath. section = 0) // group 0 {cityname = _ BJ [indexpath. row];} else {cityname = _ GD [indexpath. row];} [cell. textlabel settext: cityname]; return cell;} # title of The Pragma mark Group-(nsstring *) tableview :( uitableview *) tableview titleforheaderinsection :( nsinteger) Section {return section = 0? @ "Beijing": @ "Guangdong" ;}# subtitle at the bottom of the Pragma mark group, which is usually used to describe-(nsstring *) tableview :( uitableview *) tableview titleforfooterinsection :( nsinteger) section {return section = 0? @ "Beijing has Roast Duck": @ "Guangdong has Dongguan" ;}@ end