iOS Development Learning # Table View # (5) Populate Plain style grouping table

Source: Internet
Author: User

Select file| in the menu bar new| File ... command, select Property List, create a 1.plist file on the desktop


Core code:

#import <UIKit/UIKit.h> @interface viewcontroller:uiviewcontroller<uitableviewdatasource>{    Nsdictionary *list;    Nsarray *a;} @end
#import "ViewController.h" @interface Viewcontroller () @end @implementation viewcontroller-(void) Viewdidload {    NSString *path = [[NSBundle mainbundle]pathforresource:@ "1" oftype:@ "plist"];    Nsdictionary *dic = [[Nsdictionary Alloc]initwithcontentsoffile:path];    list = dic;    Nsarray *array = [[List allkeys]sortedarrayusingselector: @selector (compare:)];        A = array;    [Super Viewdidload]; Do any additional setup after loading the view, typically from a nib.} -(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{return [a Count];} -(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{nsstring *year = [a Objectat    Index:section];    Nsarray *moviessection = [list objectforkey:year]; return [moviessection count];} -(uitableviewcell*) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{static NSSTR    ing *cellidentifier = @ "Cell"; UITableViewCell *cell = [TableView dequeuereusableceLlwithidentifier:cellidentifier]; if (cell = = nil) {cell = [[UITableViewCell alloc]initwithstyle:uitableviewcellstyledefault Reuseidentifier:cellide    Ntifier];    } nsstring *str =[a objectatindex:[indexpath section]];    Nsarray *moviesection = [list objectforkey:str];    Cell.textLabel.text = [moviesection objectatindex:[indexpath row]]; return cell;} -(nsstring*) TableView: (UITableView *) TableView titleforheaderinsection: (nsinteger) section{nsstring *st = [a Objectat    Index:section]; Return St;}    -(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end



iOS Development Learning # Table View # (5) Populate Plain style grouping table

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.