手机通讯录实现

手机通讯录实现

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

<pre name="code" class="objc">首先重写UITableViewCell初始化方法:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.photoView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 5, 80, 80)];
        _photoView.layer.cornerRadius = 40;
        _photoView.layer.masksToBounds = YES;
        [self.contentView addSubview:_photoView];
        [_photoView release];
        
        self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(120, 5, 60, 35)];
        [self.contentView addSubview:_nameLabel];
        [_nameLabel release];
        
        self.ageLabel = [[UILabel alloc] initWithFrame:CGRectMake(200, 5, 40, 35)];
        [self.contentView addSubview:_ageLabel];
        [_ageLabel release];
        
        self.genderLabel = [[UILabel alloc] initWithFrame:CGRectMake(260, 5, 40, 35)];
        [self.contentView addSubview:_genderLabel];
        [_genderLabel release];
        
        self.phoneNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(120, 50, 200, 35)];
        [self.contentView addSubview:_phoneNumberLabel];
        [_phoneNumberLabel release];
    }
    return self;
}

@interface RootViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, retain) NSDictionary *dic;
@property (nonatomic, retain) NSArray *titles;
@end

@implementation RootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.dic =  [self readDataFromPlist];
        self.titles = [[self.dic allKeys] sortedArrayUsingSelector:@selector(compare:)];
    }
    return self;
}

- (NSDictionary *)readDataFromPlist
{
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"AddressBook-2" ofType:@"plist"];
    NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:filePath];
    return dic;
}

- (void)loadView
{
    UITableView *tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    tableView.separatorColor = [UIColor lightGrayColor];
    tableView.dataSource = self;
    tableView.delegate = self;
    tableView.rowHeight = 90;
    self.view = tableView;
    [tableView release];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"全部联系人";
}

#pragma mark - UITableViewDataSource
//设置行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.dic[self.titles[section]] count];
}

//创建cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"mark";
    StudentCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[[StudentCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier] autorelease];
    }
    NSDictionary *dic = self.dic[self.titles [indexPath.section]][indexPath.row];
    cell.photoView.image = [UIImage imageNamed:[dic objectForKey:@"imageName"]];
    cell.nameLabel.text = [self.dic[self.titles [indexPath.section]][indexPath.row] objectForKey:@"name"];
    cell.ageLabel.text = [self.dic[self.titles [indexPath.section]][indexPath.row] objectForKey:@"age"];
    cell.genderLabel.text = [self.dic[self.titles [indexPath.section]][indexPath.row] objectForKey:@"gender"];
    cell.phoneNumberLabel.text = [self.dic[self.titles [indexPath.section]][indexPath.row] objectForKey:@"phoneNumber"];
    return cell;
}

//设置分区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [self.titles count];
}

//页眉
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return self.titles[section];
}

//索引值
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    return self.titles;
}

#pragma mark - UITableViewDelegate
//当cell被选中时触发
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *str = [self.dic[self.titles [indexPath.section]][indexPath.row] objectForKey:@"phoneNumber"];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",str]]];
    //2、用UIWebView来实现。打电话结束后会返回当前应用程序:
    UIWebView *callPhoneWebVw = [[UIWebView alloc] init];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"tell://%@",str]]];
    [callPhoneWebVw loadRequest:request];
}

通过上述步骤,联系方式可以很简单.

版权声明:本文博主原创文章。博客,未经同意不得转载。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/116942.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Canny边缘检测算法原理及其VC实现详解(一)

    Canny边缘检测算法原理及其VC实现详解(一)图象的边缘是指图象局部区域亮度变化显著的部分,该区域的灰度剖面一般可以看作是一个阶跃,既从一个灰度值在很小的缓冲区域内急剧变化到另一个灰度相差较大的灰度值。图象的边缘部分集中了图象的大部分信息,图象边缘的确定与提取对于整个图象场景的识别与理解是非常重要的,同时也是图象分割所依赖的重要特征,边缘检测主要是图象的灰度变化的度量、检测和定位,自从1959提出边缘检测以来,经过五十多年的发展,已有许多中不

    2022年5月30日
    43
  • 堆糖网热门图片下载[通俗易懂]

    堆糖网热门图片下载[通俗易懂]下载目标是堆糖网热门图片,打开网页并下拉发现图片是通过ajax加载的,按F12打开开发者工具选择nerwork并筛选xhr,继续下拉网页找到ajax请求的api,如下图所示然后就可以构造请求获取包含

    2022年7月2日
    29
  • Vue(3)webstorm代码格式规范设置与vue模板配置

    Vue(3)webstorm代码格式规范设置与vue模板配置编译器代码格式规范设置通常我们写代码时,代码缩进都是4个空格,但是在前端中,据全球投票统计,建议使用2个空格来进行代码缩进。首先我们打开webstorm中的设置,如果使用的是mac的同学直接使用c

    2022年8月7日
    7
  • 树莓派串口调试助手_树莓派4b教程

    树莓派串口调试助手_树莓派4b教程原文链接:https://blog.csdn.net/itisyang/article/details/79968592最新的Raspbian串口连接没有数据输出使用ssh连接树莓派之后-sudoraspi-config-InterfacingOptions-Serial打开串口登录树莓派正常情况串口四根线连接:VCC-5VGND-GNDTX…

    2022年10月10日
    2
  • 软件工程系统设计说明书(软件详细设计说明书模板)

    1引言1.1编写目的该文档在概要设计的基础上,进一步的细化系统结构,展示了软件结构的图标,物理设计、数据结构设计、及算法设计、详细的介绍了系统各个模块是如何实现的,包括涉及到的算法,逻辑流程等。预期的读者:程序员1.2背景a. 待开发软件系统的名称:机房收费系统b. 项目的任务提出者:米新江教授c. 项目的开发者:齐智d. 项目的用户:廊坊师范学院全体在职员工及学生e. 运行该软…

    2022年4月12日
    129
  • 投影,投影矩阵,正交投影矩阵的区别_矩阵论正交投影

    投影,投影矩阵,正交投影矩阵的区别_矩阵论正交投影1、投影2、幂等矩阵3、正交投影

    2022年10月4日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号