当前位置:编程学习 > wap >>

IOS类似iphone通讯录TableView的完整demo【附源码】

初学objective-c,自己写的一个demo,有不足之处请指正:
效果图:

\


核心代码:
[plain]
- (void)viewDidLoad 

    [super viewDidLoad]; 
     
    NSArray *array = [[NSArray alloc] initWithObjects:@"你好", @"BFlower", 
                      @"CGrass", @"DFence", @"EHouse", @"FTable", @"GChair", 
                      @"HBook", @"ISwing" ,@"JWang" ,@"KDong" ,@"LNi" ,@"MHao" ,@"Na" ,@"Oa" ,@"Pa" ,@"Qa" ,@"Ra" ,@"Sa" ,@"Ta" ,@"Ua" ,@"Va" ,@"Wa" ,@"Xa" ,@"Ya" ,@"Za", nil]; 
    self.listarray = array; 
    NSLog(@"listarryCount:%d",[listarray count]); 
    secLabelArray = [[NSArray alloc] initWithObjects:@"A", @"B", @"C",@"D", @"E", @"F",@"G", @"H", @"I",@"J", @"K", @"L",@"M", @"N", @"O",@"P", @"Q", @"R",@"S", @"T", @"U",@"V", @"W", @"X",@"Y", @"Z", nil]; 
     
    NSArray *arrayA = [[NSArray alloc] initWithObjects:@"测试A1",@"测试A2", nil]; 
    NSArray *arrayB = [[NSArray alloc] initWithObjects:@"测试B1",@"测试B2",@"测试B3", nil]; 
    NSArray *arrayC = [[NSArray alloc] initWithObjects:@"测试C1",@"测试C2",@"测试C3",@"测试C4", nil]; 
    NSArray *arrayD = [[NSArray alloc] initWithObjects:@"测试D1",@"测试D2",@"测试D3",@"测试D4",@"测试D5", nil]; 
    NSArray *arrayE = [[NSArray alloc] initWithObjects:@"测试E1",@"测试E2",@"测试E3",@"测试E4",@"测试E5",@"测试E6", nil]; 
    NSArray *arrayF = [[NSArray alloc] initWithObjects:@"测试F1",@"测试F2",@"测试F3",@"测试F4",@"测试F5",@"测试F6",@"测试F7", nil]; 
    NSArray *arrayG = [[NSArray alloc] initWithObjects:@"测试G1",@"测试G2",@"测试G3",@"测试G4",@"测试G5",@"测试G6", nil]; 
    arrayDictKey = [[NSArray alloc] initWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G", nil]; 
    arrayDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:arrayA,[arrayDictKey objectAtIndex:0], 
                                                                    arrayB,[arrayDictKey objectAtIndex:1], 
                                                                    arrayC,[arrayDictKey objectAtIndex:2], 
                                                                    arrayD,[arrayDictKey objectAtIndex:3], 
                                                                    arrayE,[arrayDictKey objectAtIndex:4], 
                                                                    arrayF,[arrayDictKey objectAtIndex:5], 
                                                                    arrayG,[arrayDictKey objectAtIndex:6], 
                                                                            nil]; 
    NSLog(@"arrayrow:%d",[[arrayDict objectForKey:[arrayDictKey objectAtIndex:1]] count]); 
     
     tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)]; 
    [tableView setDelegate:self]; 
    [tableView setDataSource:self]; 
    [self.view addSubview:tableView]; 
    [tableView release]; 
 
     
    // Do any additional setup after loading the view. 

 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView  
{  
    //* 出现几组 
    //if(aTableView == self.tableView) return 27; 
    return [arrayDict count];  

 
//*字母排序搜索 
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView 

    //* 字母索引列表 
    /*NSMutableArray *toBeReturned = [[NSMutableArray alloc]init]; 
     
    for(char c= '

补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,