手机通讯录实现

手机通讯录实现

大家好,又见面了,我是全栈君,今天给大家准备了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)
上一篇 2022年1月12日 下午11:00
下一篇 2022年1月13日 上午6:00


相关推荐

  • 求素数

    求素数求素数

    2022年4月24日
    49
  • java 遍历map 方法[通俗易懂]

    遍历方法一( entrySet()遍历):Iteratorit=tempMap.entrySet().iterator();while(it.hasNext()){Map.Entryentry=(Map.Entry)it.next();Objectkey=entry.getKey();Objectvalue=entry.getVal

    2022年4月15日
    62
  • 电脑ping命令显示不是内部命令_cmd一直ping的命令

    电脑ping命令显示不是内部命令_cmd一直ping的命令在cmd中用PING命令时,出现’Ping’不是内部或外部命令,也不是可运行的程序或批处理文件。先了解一下内容:1、可执行文件、命令文件和批处理文件以.exe或者.com或者.bat为扩展名的文件分别被称为可执行文件、命令文件和批处理文件。2、外部命令和内部命令DOS命令可以分为外部命令和内部命令,内部命令包含在一个名为command.com的文件,在系统启动时候驻留在内存中。外部命令是保存在c…

    2025年12月3日
    5
  • acwing-1142. 繁忙的都市[通俗易懂]

    acwing-1142. 繁忙的都市[通俗易懂]城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造。城市C的道路是这样分布的:城市中有 n 个交叉路口,编号是 1∼n,有些交叉路口之间有道路相连,两个交叉路口之间最多有一条道路相连接。这些道路是 双向 的,且把所有的交叉路口直接或间接的连接起来了。每条道路都有一个分值,分值越小表示这个道路越繁忙,越需要进行改造。但是市政府的资金有限,市长希望进行改造的道路越少越好,于是他提出下面的要求:1.改造的那些道路能够把所有的交叉路口直接或间接的连通起来。2.在满足

    2022年8月9日
    14
  • 【超分辨】SRGAN详解及其pytorch代码解释

    【超分辨】SRGAN详解及其pytorch代码解释SRGAN 是一个超分辨网络 利用生成对抗网络的方法实现图片的超分辨 本文解释了 SRGAN 原理 同时通过 pytorch 代码实现

    2025年10月14日
    7
  • AQS原理及用法_aqs是什么意思

    AQS原理及用法_aqs是什么意思AQS原理及用法1AQS简介AQS全称为AbstractQueuedSynchronizer,是Java中的一个抽象类。AQS是一个用于构建锁、同步器、协作工具类的工具类(框架)。有了AQS之后,更多的协作工具类都可以方便得被写出来。有了AQS,构建线程协作类就容易多了。控制并发流程的类,都需要线程等待和唤醒的功能,这是这些类的共同特点,因此可以抽象出一个基类,这就是AQS。AQS广泛用于控制并发流程的类,如下图:其中Sync是这些类中都有的内部类,其结构如下:

    2025年5月23日
    8

发表回复

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

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