American Mission HD (5)-Select city

Source: Internet
Author: User

Djselectcityviewcontroller.m

#import "DJSelectCityViewController.h"#import "DJConstantValue.h"#import "DJCityGroup.h"#import "MJExtension.h"@interfaceDjselectcityviewcontroller () <UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate>/** City Group List*/@property (nonatomic,strong) Nsmutablearray*citygroups, @property (weak, nonatomic) Iboutlet UITableView*Citytableview;@end@implementationDjselectcityviewcontroller- (void) viewdidload {[Super viewdidload]; Self.title=@"Select City"; //set the right index bar font colorSelf.cityTableView.sectionIndexColor =[Uicolor Blackcolor];    [Self setupnavleftitem];    [Self loadcitydata]; }- (void) Setupnavleftitem {Uibarbuttonitem*closeitem = [Uibarbuttonitem itemwithtarget:self action: @selector (Close) Image:@"Btn_navigation_close"Highlighimage:@"Btn_navigation_close_hl"]; Self.navigationItem.leftBarButtonItem=Closeitem;}/** Load City Data*/- (void) Loadcitydata {self.citygroups= [Djcitygroup mj_objectarraywithfilename:@"citygroups.plist"]; }/** Close the current interface*/- (void) Close {[Self dismissviewcontrolleranimated:yes completion:nil];}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}#pragmaMark-uitableview Data Source Method-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView {returnSelf.cityGroups.count;}-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {Djcitygroup*citygroup =Self.citygroups[section]; returnCityGroup.cities.count; }-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {StaticNSString *id =@"Citygroup"; UITableViewCell*cell =[TableView Dequeuereusablecellwithidentifier:id]; if(!cell) {Cell=[[UITableViewCell alloc] Initwithstyle:uitableviewcellstylesubtitle Reuseidentifier:id]; } Djcitygroup*citygroup =Self.citygroups[indexpath.section]; NSString*cityname =Citygroup.cities[indexpath.row]; Cell.textLabel.text=CityName; returncell;}#pragmaMark-tableview Proxy Method-(NSString *) TableView: (UITableView *) TableView titleforheaderinsection: (nsinteger) Section {Djcitygroup*citygroup =Self.citygroups[section]; returnCitygroup.title; }-(nsarray<nsstring *> *) Sectionindextitlesfortableview: (UITableView *) TableView {return[Self.citygroups Valueforkeypath:@"title"];}#pragmaMark-uisearchbar Proxy method/** Searchbar start editing*/- (void) Searchbartextdidbeginediting: (Uisearchbar *) Searchbar {//Hide Navigation bar[Self.navigationcontroller Setnavigationbarhidden:yes Animated:yes]; }/** Searchbar End Edit*/- (void) Searchbartextdidendediting: (Uisearchbar *) Searchbar {//Show navigation bar[Self.navigationcontroller setnavigationbarhidden:no animated:yes];}@end

Final effect:

American Mission HD (5)-Select city

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.