IOS ui09_ Multiple TableView

Source: Internet
Author: User

////MAINVIEWCONTROLLER.M//ui09_ multiple TableView////Created by Dllo on 15/8/10.//Copyright (c) 2015 Zhozhicheng. All rights reserved.//#import "MainViewController.h"  @interface mainviewcontroller () <Uitableviewdatasource,  Uitableviewdelegate>@property(nonatomic, retain)Nsmutablearray*proarr;@property(nonatomic, retain)UITableView*tableview1;@property(nonatomic, retain)UITableView*tableview2;@property(nonatomic, retain)UITableView*TABLEVIEW3;@property(nonatomic, retain)Nsmutablearray*cityarr;@property(nonatomic, retain)Nsmutablearray*zonearr;@end @implementation mainviewcontroller -(void) dealloc{[_proarr release];    [_cityarr release];    [_zonearr release]; [SuperDealloc];} -(Instancetype) Initwithnibname: (NSString*) Nibnameornil Bundle: (NSBundle*) nibbundleornil{ Self=[SuperInitwithnibname:nibnameornil Bundle:nibbundleornil];if( Self) {        [ SelfCreatedata]; }return  Self;} -(void) createdata{//path to file    NSString*[email protected]"/users/dllo/desktop/job/ui08_tableview Provinces and Cities Dictionary array/ui08_tableview Provincial and regional dictionary array/area.txt";NSString*str =[NSStringStringwithcontentsoffile:path encoding:nsutf8stringencoding Error:Nil];Nsarray*strarr=[str componentsseparatedbystring:@"\ n"]; Self. Proarr=[NsmutablearrayArray];//Province Urban array     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 setvalue:temp forkey:@"CityName"];Nsmutablearray*zonearr=[NsmutablearrayArray]; [Citydic Setvalue: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. View. BackgroundColor=[[UicolorAlloc] initwithpatternimage:[UIImageimagenamed:@"C8abca078d303faf9aa32506ef1927a2.jpg"]]; Self. View. Alpha=0.5; Self. Navigationcontroller. Navigationbar. Translucent=NO;//A page has three tableview, to interact with each other, click the province to display the corresponding city, click the city to show the corresponding area    //paved with three x TableView     Self. TableView1=[[UITableViewAlloc] Initwithframe:cgrectmake (0,0, Self. View. Frame. Size. Width/3, Self. View. Frame. Size. Height- -) Style:uitableviewstyleplain]; [ Self. ViewAddsubview: Self. TableView1]; [ Self. TableView1Release]; Self. TableView1. Delegate= Self; Self. TableView1. DataSource= Self; Self. TableView1. Separatorstyle= Uitableviewcellseparatorstylenone; Self. TableView2=[[UITableViewAlloc] Initwithframe:cgrectmake ( Self. View. Frame. Size. Width/3,0, Self. View. Frame. Size. Width/3, Self. View. Frame. Size. Height- -) Style:uitableviewstyleplain]; [ Self. ViewAddsubview: Self. TableView2]; [ Self. TableView2Release]; Self. TableView2. Delegate= Self; Self. TableView2. DataSource= Self; Self. TableView2. Separatorstyle= Uitableviewcellseparatorstylenone; Self. TABLEVIEW3=[[UITableViewAlloc] Initwithframe:cgrectmake (2* Self. View. Frame. Size. Width/3,0, Self. View. Frame. Size. Width/3, Self. View. Frame. Size. Height- -) Style:uitableviewstyleplain]; [ Self. ViewAddsubview: Self. TABLEVIEW3]; [ Self. TABLEVIEW3Release]; Self. TABLEVIEW3. Delegate= Self; Self. TABLEVIEW3. DataSource= Self; Self. TABLEVIEW3. Separatorstyle= Uitableviewcellseparatorstylenone;} -(Nsinteger) TableView: (UITableView*) TableView numberofrowsinsection: (Nsinteger) section{if(tableview== Self. TableView1) {return  Self. Proarr. Count; }Else if(TableView = = Self. TableView2)return  Self. Cityarr. Count;Else{return  Self. Zonearr. Count; }}//Create cell-(UITableViewCell*) TableView: (UITableView*) TableView Cellforrowatindexpath: (Nsindexpath*) indexpath{if(TableView = = Self. TableView1) {Static NSString*[email protected]"Reuse";UITableViewCell*cell =[tableview Dequeuereusablecellwithidentifier:reuse];if(!cell) {Cell =[[[UITableViewCellAlloc] initwithstyle:uitableviewcellstylevalue1 Reuseidentifier:reuse] autorelease]; }nsmutabledictionary*prodic= Self. Proarr[Indexpath. Row]; Cell. Textlabel. Text=prodic[@"Proname"];returnCell }Else if(TableView = = Self. TableView2){Static NSString*[email protected]"Cityresuse";UITableViewCell*cell =[tableview Dequeuereusablecellwithidentifier:cityresuse];if(!cell) {Cell =[[[UITableViewCellAlloc] initwithstyle:uitableviewcellstylevalue1 Reuseidentifier:cityresuse] autorelease]; }nsmutabledictionary*citydic= Self. Cityarr[Indexpath. Row]; Cell. Textlabel. Text=citydic[@"CityName"];returnCell }Else{Static NSString*[email protected]"Zonereuse";UITableViewCell*cell=[tableview Dequeuereusablecellwithidentifier:zonereuse];if(!cell) {Cell =[[[UITableViewCellAlloc] initwithstyle:uitableviewcellstylevalue1 Reuseidentifier:zonereuse] autorelease]; } cell. Textlabel. Text= Self. Zonearr[Indexpath. Row];returnCell }}//Click-(void) TableView: (UITableView*) TableView Didselectrowatindexpath: (Nsindexpath*) indexpath{//Determine which TableView is currently clicked    if(TableView = = Self. TableView1) {//Find out which province is currently clicked        nsmutabledictionary*prodic= Self. Proarr[Indexpath. Row];//Find a city array         Self. Cityarr=prodic[@"Cityarr"];//Refresh[ Self. TableView2Reloaddata]; }Else if(TableView = = Self. TableView2){nsmutabledictionary*citydic= Self. Cityarr[Indexpath. Row]; Self. Zonearr=citydic[@"Zonearr"]; [ Self. TABLEVIEW3Reloaddata]; }}- (void) Didreceivememorywarning {[SuperDidreceivememorywarning];//Dispose of any resources, can be recreated.}/ * #pragma mark-navigation//in a storyboard-based application, you'll often want to do a little preparation before navigation-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {//Get the new view controller using    [Segue Destinationviewcontroller]. Pass the selected object to the new view Controller.} */@end

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

IOS ui09_ Multiple TableView

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.