(1) Create a project Telephonebook
(2) Open the Main.storyboard file, drag the tab bar controller from view Kuto to the canvas.
(3) In the toolbar, select the Show the Attributes Inspector icon, under View Controller, select the IS Initial View controller.
(4) Remove the existing View Controller view controllers in the canvas, and then delete the tab Bar Controller tab bar controllers associated with the views Controller-item 1 and controller-item2 view controllers.
(5) Drag one of the navigation controller navigation controllers from the view library into the canvas.
(6) Change the tab bar Controller tab bar controllers associated view to navigation controller navigation controllers.
Core code:
TableView1.h
#import <UIKit/UIKit.h> @interface Tableview1:uitableviewcontroller<uitableviewdatasource, uitableviewdelegate>{ Nsmutablearray *a;} -(ibaction) AA: (ID) sender;-(ibaction) BB: (ID) sender; @end
Tableview1.m
#import "TableView1.h" @interface TableView1 () @end @implementation tableview1-(void) viewdidload {a = [[Nsmutablearray] alloc]initwithobjects:@ "Ant", @ "Alpaca", @ "Albatross", @ "Badger", @ "bat", @ "Bear", @ "cat", @ "calf", @ "cattle", nil]; [Super Viewdidload]; }-(void) didreceivememorywarning {[Super didreceivememorywarning];} #pragma mark-table View data source-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView {return 1;} -(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {return [a count];} -(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {static Nsstri ng *cellidentifier = @ "Cell"; UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:cellidentifier]; if (cell = = nil) {cell = [[UITableViewCell alloc]initwithstyle:uitableviewcellstyledefault Reuseidentifier:cellide Ntifier]; } Cell.textLabel.text = [a Objectatindex:[indexpath row]]; return cell;} -(void) TableView: (UITableView *) TableView Commiteditingstyle: (uitableviewcelleditingstyle) Editingstyle Forrowatindexpath: (Nsindexpath *) Indexpath {if (Editingstyle = = Uitableviewcelleditingstyledelete) {[A RemoveO BjectAtIndex:indexPath.row]; [TableView Deleterowsatindexpaths:[nsarray Arraywithobject:indexpath] Withrowanimation: Uitableviewrowanimationautomatic]; }}-(ibaction) AA: (ID) Sender {[self setediting:yes];} -(Ibaction) BB: (ID) Sender {[self setediting:no];} @end
TableView2.h
#import <UIKit/UIKit.h> @interface Tableview2:uitableviewcontroller<uitableviewdatasource, uitableviewdelegate>{ nsdictionary *list; Nsarray *ff; Iboutlet Uisearchbar *searchbar; BOOL Issearchon; BOOL Canselectrow; Nsmutablearray *listofmovies; Nsmutablearray *searchresult;} -(void) Searchmoviestableview; @end
Tableview2.m
#import "TableView2.h" @interface TableView2 () @end @implementation tableview2-(void) viewdidload {nsstring *path = [[NS] Bundle mainbundle]pathforresource:@ "1" oftype:@ "plist"]; Nsdictionary *dic = [[Nsdictionary Alloc]initwithcontentsoffile:path]; list = dic; Nsarray *array = [[List allkeys]sortedarrayusingselector: @selector (compare:)]; FF = array; Self.tableView.tableHeaderView = Searchbar; Searchbar.autocorrectiontype = Uitextautocorrectiontypeyes; Listofmovies = [[Nsmutablearray alloc]init]; For (NSString *year in array) {Nsarray *movies = [list objectforkey:year]; For (NSString *title in movies) {[Listofmovies addobject:title]; }} searchresult = [[Nsmutablearray alloc]init]; Issearchon = NO; Canselectrow = YES; [Super Viewdidload]; }-(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} #pragma mark-table View data source-(Nsindexpath*) TableView: (UITableView *) TableView Willselectrowatindexpath: (Nsindexpath *) indexpath{if (canselectrow) { return indexpath; }else{return nil; }}-(void) Searchbar: (uisearchbar*) Searchbar textdidchange: (NSString *) searchtext{if ([searchtext length] > 0) { Issearchon = YES; Canselectrow = YES; self.tableView.scrollEnabled = YES; [Self searchmoviestableview]; }else{Issearchon = NO; Canselectrow = NO; self.tableView.scrollEnabled = NO; } [Self.tableview reloaddata];} -(void) searchbarsearchbuttonclicked: (uisearchbar*) searchbar{[self searchmoviestableview];} -(void) searchmoviestableview{[SearchResult removeallobjects]; For (NSString *str in listofmovies) {nsrange titleresultrange = [str rangeOfString:searchBar.text Options:nscasein Sensitivesearch]; if (Titleresultrange.length > 0) {[SearchResult addobject:str]; }}}-(Nsinteger) numberofsectionsinTableView: (UITableView *) tableview{if (Issearchon) {return 1; }else{return [FF Count]; }}-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {if (Issearchon) {R Eturn [SearchResult Count]; }else{nsstring *year = [ff objectatindex:section]; Nsarray *moviesection = [list objectforkey:year]; return [moviesection Count]; }}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {static NSSt Ring *cellidentifier = @ "Cell"; UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:cellidentifier]; if (cell = = nil) {cell = [[UITableViewCell alloc]initwithstyle:uitableviewcellstyledefault Reuseidentifier:cellide Ntifier]; } if (Issearchon) {nsstring *cellvalue = [SearchResult objectAtIndex:indexPath.row]; Cell.textLabel.text = Cellvalue; }else{nsstring *year = [ff Objectatindex:[indexpathSection]]; Nsarray *moviesection = [list objectforkey:year]; Cell.textLabel.text = [moviesection objectatindex:[indexpath row]]; } return cell; -(nsstring*) TableView: (UITableView *) TableView titleforheaderinsection: (nsinteger) section{nsstring *year = [ff objec Tatindex:section]; if (Issearchon) {[Searchbar resignfirstresponder]; return nil; }else{return year; }} @end
iOS Development Learning # Simple Address Book Making #