UI TableView edition China Provinces and Cities--3 pages

Source: Internet
Author: User

Remember the Chinese provinces and cities that I wrote before?
Now we use TableView to show him.
It uses the value of the previous backward property.
The first page is as follows, altogether 31 provinces

#import "ProViewController.h" #import "CityViewController.h"  @interface proviewcontroller () <Uitableviewdatasource,uitableviewdelegate >@property(nonatomic, retain)Nsmutablearray*proarr;@end @implementation proviewcontroller - (void) dealloc{[_proarr release]; [SuperDealloc];} -(Instancetype) Initwithnibname: (NSString*) Nibnameornil Bundle: (NSBundle*) nibbundleornil{ Self= [SuperInitwithnibname:nibnameornil Bundle:nibbundleornil];if( Self) {        [ SelfCreatedata]; }return  Self;} - (void) createdata{NSString*path = @"/users/dllo/desktop/ui study/ui08tableview Provinces and cities./ui08tableview provinces and cities./area.txt";NSString*STR = [NSStringStringwithcontentsoffile:path encoding:nsutf8stringencoding Error:Nil];Nsarray*strarr = [Str componentsseparatedbystring:@"\ n"]; Self. Proarr= [NsmutablearrayArray]; for(NSString*temp in Strarr) {if(! [Temp hasprefix:@" "]) {nsmutabledictionary*prodic = [nsmutabledictionaryDictionary]; [Prodic setobject:temp forkey:@"Proname"];Nsmutablearray*cityarr = [NsmutablearrayArray]; [Prodic Setobject:cityarr forkey:@"Cityarr"]; [ Self. ProarrAddobject:prodic]; }Else if([Temp hasprefix:@"  "]&&! [Temp hasprefix:@"    "]){nsmutabledictionary*citydic = [nsmutabledictionaryDictionary]; [Citydic setobject:temp forkey:@"CityName"];Nsmutablearray*zonearr = [NsmutablearrayArray]; [Citydic Setobject:zonearr forkey:@"Zonearr"];nsmutabledictionary*prodic = [ Self. ProarrLastobject];Nsmutablearray*cityarr = prodic[@"Cityarr"];        [Cityarr Addobject:citydic]; }Else{nsmutabledictionary*prodic = [ Self. ProarrLastobject];Nsmutablearray*cityarr = prodic[@"Cityarr"];nsmutabledictionary*citydic = [Cityarr lastobject];Nsmutablearray*zonearr = citydic[@"Zonearr"];        [Zonearr addobject:temp]; }    }}- (void) Viewdidload {[SuperViewdidload];additional setup after loading the view.     Self. Navigationcontroller. Navigationbar. Translucent=NO; Self. View. BackgroundColor= [UicolorRedcolor]; Self. Title= @"Chinese provincial name";UITableView*tableview = [[UITableViewAlloc] Initwithframe:cgrectmake (0,0, Self. View. Frame. Size. Width, Self. View. Frame. Size. Height- -) Style:uitableviewstyleplain]; [ Self. ViewAddsubview:tableview];    [TableView release]; TableView. Delegate= Self; TableView. DataSource= Self;////read out plist file contents//NSString *path = [[NSBundle mainbundle]pathforresource:@ "Student " oftype:@ "plist"];//Nsmutabledictionary *dic = [Nsmutabledictionary Dictionarywithcontentsoffile:path];//NSLog (@ "%@", dic);}- (Nsinteger) TableView: (UITableView*) TableView numberofrowsinsection: (Nsinteger) section{return  Self. Proarr. Count;} - (UITableViewCell*) TableView: (UITableView*) TableView Cellforrowatindexpath: (Nsindexpath*) indexpath{Static  NSString*reuse = @"Reuse";UITableViewCell*cell = [TableView dequeuereusablecellwithidentifier:reuse];if(!cell) {cell = [[[UITableViewCellAlloc] Initwithstyle:uitableviewcellstyledefault Reuseidentifier:reuse] autorelease]; }nsmutabledictionary*prodic = Self. Proarr[Indexpath. Row]; Cell. Textlabel. Text= prodic[@"Proname"];returnCell;} - (void) TableView: (UITableView*) TableView Didselectrowatindexpath: (Nsindexpath*) indexpath{Cityviewcontroller *CITYVC = [[Cityviewcontroller alloc] init]; [ Self. NavigationcontrollerPUSHVIEWCONTROLLER:CITYVC Animated:YES]; [CITYVC release];//Province dictionary    nsmutabledictionary*prodic = Self. Proarr[Indexpath. Row];//province corresponding to the city arrayCityvc. Cityarr= prodic[@"Cityarr"];}

Second page:

#import "CityViewController.h" #import "ZoomViewController.h"  @interface cityviewcontroller () <Uitableviewdatasource, uitableviewdelegate >@end @implementation cityviewcontroller - (void) dealloc{[_cityarr release]; [SuperDealloc];} - (void) Viewdidload {[SuperViewdidload];additional setup after loading the view.     Self. View. BackgroundColor= [UicolorBluecolor];//NSLog (@ "%@", Self.cityarr);      Self. Title= @"City Name";UITableView*tableview = [[UITableViewAlloc] Initwithframe:cgrectmake (0,0, Self. View. Frame. Size. Width, Self. View. Frame. Size. Height- -) style:uitableviewstylegrouped]; [ Self. ViewAddsubview:tableview];    [TableView release]; TableView. Delegate= Self; TableView. DataSource= Self;} - (Nsinteger) TableView: (UITableView*) TableView numberofrowsinsection: (Nsinteger) section{return  Self. Cityarr. Count;} - (UITableViewCell*) TableView: (UITableView*) TableView Cellforrowatindexpath: (Nsindexpath*) indexpath{Static NSString*reuse = @"Reuse";UITableViewCell*cell = [TableView dequeuereusablecellwithidentifier:reuse];if(!cell) {cell = [[[UITableViewCellAlloc] initwithstyle:uitableviewcellstylevalue1 Reuseidentifier:reuse] autorelease]; }nsmutabledictionary*citydic = Self. Cityarr[Indexpath. Row]; Cell. Textlabel. Text= citydic[@"CityName"];returnCell;} - (void) TableView: (UITableView*) TableView Didselectrowatindexpath: (Nsindexpath*) indexpath{Zoomviewcontroller *ZONEVC = [[Zoomviewcontroller alloc] init]; [ Self. NavigationcontrollerPUSHVIEWCONTROLLER:ZONEVC Animated:YES]; [ZONEVC release];nsmutabledictionary*citydic = Self. Cityarr[Indexpath. Row]; Zonevc. Zonearr= citydic[@"Zonearr"];}

The third page:

#import "ZoomViewController.h"  @interface zoomviewcontroller () <Uitableviewdatasource,  Uitableviewdelegate,uialertviewdelegate>@property(nonatomic, retain) Uialertview *alet;@end @implementation zoomviewcontroller - (void) dealloc{[_zonearr release];    [_alet release]; [SuperDealloc];} - (void) Viewdidload {[SuperViewdidload];additional setup after loading the view.      Self. Title= @"District name"; Self. View. BackgroundColor= [UicolorGreencolor];UITableView*tableview = [[UITableViewAlloc] Initwithframe:cgrectmake (0,0, Self. View. Frame. Size. Width, Self. View. Frame. Size. Height- -) Style:uitableviewstyleplain]; [ Self. ViewAddsubview:tableview];    [TableView release]; TableView. Delegate= Self; TableView. DataSource= Self; TableView. RowHeight= -; Self. Alet= [[Uialertview alloc] initwithtitle:@"Would you like to return to the city name?"MessageNilDelegate Selfcancelbuttontitle:@"Return to City name"otherbuttontitles:@"Back to Home",@"Cancel",Nil];} - (Nsinteger) TableView: (UITableView*) TableView numberofrowsinsection: (Nsinteger) section{return  Self. Zonearr. Count;} - (UITableViewCell*) TableView: (UITableView*) TableView Cellforrowatindexpath: (Nsindexpath*) indexpath{Static NSString*reuse = @"Reuse";UITableViewCell*cell = [TableView dequeuereusablecellwithidentifier:reuse];if(!cell) {cell = [[[UITableViewCellAlloc] Initwithstyle:uitableviewcellstylesubtitle Reuseidentifier:reuse] autorelease]; } cell. Textlabel. Text= Self. Zonearr[Indexpath. Row];returnCell;} - (void) TableView: (UITableView*) TableView Didselectrowatindexpath: (Nsindexpath*) indexpath{[ Self. AletShow];} - (void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (Nsinteger) buttonindex{if(Buttonindex = =0) {        [ Self. NavigationcontrollerPopviewcontrolleranimated:YES]; }Else if(Buttonindex = =1){        [ Self. NavigationcontrollerPoptorootviewcontrolleranimated:YES]; }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

UI TableView edition China Provinces and Cities--3 pages

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.