wk125874 2015-05-08 09:42 采纳率: 0%
浏览 5180

OC 实现简单通讯录操作

实现简单通讯录操作。
 1、定义联系⼈人类Contact。实例变量:姓名、性别、电话号码、住址、分组名称。⽅方 法:初始化⽅方法(姓名、电话号码)、显⽰示联系⼈人信息
 2、在main.m中定义可变数组,管理所有联系⼈人。可以添加新联系⼈人对象,如果姓名 或电话号码为空,打印添加失败。

3、获取某个分组下的所有联系⼈人。

4、根据电话号码搜索联系⼈人。

5、获取所有⼥女性联系⼈人

6、根据姓名删除联系⼈人

7、删除某个分组全部联系⼈人 

8、展⽰示通讯录中所有联系⼈人

9、选做:定义AddressBook类,封装上述功能。

  • 写回答

1条回答 默认 最新

  • 王大锤子呦 2015-05-08 09:59
    关注
    - (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= 'A';c<='Z';c++)  
    
            [toBeReturned addObject:[NSString stringWithFormat:@"%c",c]];*/  
    
        return arrayDictKey;  
    
        /*NSMutableArray *newarr=[[NSMutableArray alloc]initWithArray:listarray];  
        [newarr addObject:@"{search}"]; //等价于[arr addObject:UITableViewIndexSearch];  
        return newarr;*/  
    
    }  
    
    - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index  
    {    
        //搜索时显示按索引第几组   
        NSInteger count = 0;  
        NSLog(@"%@",title);  
        for(NSString *character in arrayDictKey)  
        {  
    
            if([character isEqualToString:title])  
            {  
    
                return count;  
    
            }  
    
            count ++;  
    
        }  
    
        return count;  
    
    }  
    
    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section  
    {  
    
        /*if([listarray count]==0)  
    
        {  
    
            return @"";  
    
        }*/  
    
            //return [listarray objectAtIndex:section];   //*分组标签  
        return [arrayDictKey objectAtIndex:section];  
    
    }  
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {   
        //return [self.listarray count];    //*每组要显示的行数  
        //NSInteger i = [[listarray objectAtIndex:section] ]  
       NSInteger i =  [[arrayDict objectForKey:[arrayDictKey objectAtIndex:section]] count];  
        return i;  
    }  
    
    -(UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath{     
        //返回类型选择按钮    
    
        return UITableViewCellAccessoryDisclosureIndicator;   //每行右边的图标  
    }    
    - (UITableViewCell *)tableView:(UITableView *)tableview   
             cellForRowAtIndexPath:(NSIndexPath *)indexPath {   
    
        static NSString *TableSampleIdentifier = @"TableSampleIdentifier";   
    
        UITableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:   
                                 TableSampleIdentifier];   
        if (cell == nil) {   
            cell = [[UITableViewCell alloc]   
                    initWithStyle:UITableViewCellStyleDefault   
                    reuseIdentifier:TableSampleIdentifier];  
        }   
    
        NSUInteger row = [indexPath row];  
        NSUInteger sectionMy = [indexPath section];  
        NSLog(@"sectionMy:%d",sectionMy);  
    
        cell.textLabel.text = [[arrayDict objectForKey:[arrayDictKey objectAtIndex:sectionMy]] objectAtIndex:row]; //每一行显示的文字  
    
        NSString *str=  [NSString stringWithFormat: @"%d", row];  
    
        UIImage *image = [UIImage imageNamed:str];   
        cell.imageView.image = image;   
        UIImage *highLighedImage = [UIImage imageNamed:@"1.png"];   
    
        cell.imageView.highlightedImage = highLighedImage; //选中一行时头部图片的改变  
        return cell;   
    }  
    //划动cell是否出现del按钮  
    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {  
    
    
        return YES;  //是否需要删除图标  
    }  
    //编辑状态(不知道干什么用)  
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle   
    forRowAtIndexPath:(NSIndexPath *)indexPath  
    {     
    
        [self viewDidLoad];  
    }  
    
    //选中时执行的操作  
    - (NSIndexPath *)tableView:(UITableView *)tableView   
      willSelectRowAtIndexPath:(NSIndexPath *)indexPath {   
        NSUInteger row = [indexPath row];  
        if (row%2 == 0) {  
            NSUInteger row = [indexPath row];   
            NSString *rowValue = [listarray objectAtIndex:row];   
    
            NSString *message = [[NSString alloc] initWithFormat:   
                                 @"You selected %@", rowValue];   
            UIAlertView *alert = [[UIAlertView alloc]   
                                  initWithTitle:@"Row Selected!"   
                                  message:message   
                                  delegate:nil   
                                  cancelButtonTitle:@"Yes I Did"   
                                  otherButtonTitles:nil];   
            [alert show];   
    
        }  
        return indexPath;   
    }  
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{  
    
        //这里控制值的大小  
        return 50.0;  //控制行高  
    
    }  
    
    评论

报告相同问题?

悬赏问题

  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败