:
Post-click:
Engineering Drawing:
Code:
ViewController.h
#import <UIKit/UIKit.h>@interface Viewcontroller:uiviewcontroller< Uitableviewdatasource,uitableviewdelegate>{ *mytableview; *DataArray; *Indexarray;} @end
Viewcontroller.m
#import "ViewController.h"@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib.Mytableview= [[UITableView alloc]initwithframe:cgrectmake (0,0, the, -)]; Mytableview.datasource=Self ; Mytableview.Delegate=Self ; //Set Index to orangeMytableview.sectionindexcolor =[Uicolor Orangecolor]; [Self.view Addsubview:mytableview]; for(Charc ='A'; C <='Z'; C++ ) { if(!DataArray) {DataArray=[[Nsmutablearray alloc]init]; } if(!Indexarray) {Indexarray=[[Nsmutablearray alloc]init]; } [Indexarray addobject:[nsstring stringWithFormat:@"%c", c]]; [DataArray addobject:[nsstring stringWithFormat:@"%c", c]]; [DataArray addobject:[nsstring stringWithFormat:@"%c", c]]; [DataArray addobject:[nsstring stringWithFormat:@"%c", c]]; } NSLog (@"----indexarray--%@", Indexarray); NSLog (@"------DataArray----%@", DataArray);}#pragma-mark-uitableviewdelegate-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{return[Indexarray Count];}-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{return 3;}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{StaticNSString *cellidentifier =@"Cell"; UITableViewCell*cell =[TableView Dequeuereusablecellwithidentifier:cellidentifier]; if(Cell = =Nil) {Cell=[[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; } Cell.textLabel.text= [DataArray objectAtIndex:indexPath.section *3+Indexpath.row]; returncell;}-(Nsarray *) Sectionindextitlesfortableview: (UITableView *) tableview{returnIndexarray;}-(Nsinteger) TableView: (UITableView *) TableView sectionforsectionindextitle: (NSString *) title Atindex: (Nsinteger) index{Nsinteger Count=0; for(NSString *characterinchIndexarray) { if([character Isequaltostring:title]) {returncount; } Count++; } return 0;}-(NSString *) TableView: (UITableView *) TableView titleforheaderinsection: (nsinteger) section{return[Indexarray objectatindex:section];}
UITableView with index