Uitableview learning --- 1

Source: Internet
Author: User
# 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
 
 




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.