Xcode利用CoreData编成简易内置通讯录

最近看了一下苹果手机通讯录,感觉挺高端的,就随便做了一下它的那些效果,正好也可以复习复习CoreData
CoreData里的代码我就不说了,就是最基本的代码。里面分别有姓名,公司名,手机号码,和类型四种数据 四个都是字符串类型。

这里是显示页的ViewController

//
//  ViewController.m
//  TongXunLu
//
//  Created by ChuXiang on 15/12/25.
//  Copyright © 2015年 ChuXiang. All rights reserved.
//

#import "ViewController.h"
#import "AddContactViewController.h"
#import "SelectData.h"
#import "Contact.h"
#import "CoreDataManager.h"
@interface ViewController () <UITableViewDataSource,UITableViewDelegate, myDelegate>
@property (nonatomic,strong) UITableView *nameTable;
@property (nonatomic,strong) NSArray *sectionTitleArray;//总标题数组

@property (nonatomic,strong) NSMutableArray *sectionArray;//小标题数组
//全部数据数组
@property (nonatomic,strong) NSMutableArray *cellTextArray;// 装有cell的数组
@property (nonatomic,strong) SelectData *selectData; //CoreData的增删改查
@property (nonatomic,strong) NSArray *result; //从CoreData中取出总数据
@property (nonatomic,strong) CoreDataManager *manager;
@end

@implementation ViewController

- (void)viewDidLoad {
    [superviewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.navigationItem.title =@"所有联系人";
    self.selectData = [[SelectDataalloc] init];
    self.result = [self.selectDatagetAllData];

    self.cellTextArray = [NSMutableArrayarrayWithCapacity:0];

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAddtarget:selfaction:@selector(rightBarButtonDidPress:)];
    [self.viewaddSubview:self.nameTable];

    self.sectionTitleArray = [[NSArrayalloc] 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];
    self.sectionArray = [NSMutableArrayarrayWithCapacity:0];
    [selfDataAnalysis];

}

#pragma mark - 数据分析
- (void) DataAnalysis {
    self.selectData = [[SelectDataalloc] init];
    self.result = [self.selectDatagetAllData];
       for (int i =0; i < self.sectionTitleArray.count; i++) {
           for (Contact *contactin self.result) {
              if ([contact.firstStringisEqualToString:self.sectionTitleArray[i]]) {
                [self.sectionArrayaddObject:self.sectionTitleArray[i]];
                break;
            }
        }
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值