手机通讯录实现

手机通讯录实现

大家好,又见面了,我是全栈君,今天给大家准备了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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 常用进程调度算法_进程调度算法例题

    常用进程调度算法_进程调度算法例题写在前面:我是【程序员宝藏】的宝藏派发员,致力于创作原创干货。我热爱技术、热爱开源与分享,创作的【计算机基础面试问题】系列文章和【计算机基础主干知识】系列文章广受好评!后期会创作更多优质原创系列文章!如果您对计算机基础知识、编程等感兴趣,可以关注我,我们一起成长!本人力荐:如果觉得CSDN排版不够美观,欢迎来我的个人原创公zong号【程序员宝藏】(号如其名,诚不欺你!)查看有红色重点标记和排版美观的全系列文章(不细你来找我要红包)参考链接:TCP三次握手四次挥手好多同学问我要pdf版,我干脆.

    2022年9月29日
    3
  • JAVA如何调用对方http接口得到返回数据

    JAVA如何调用对方http接口得到返回数据https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=”手机号码”jsp代码:<formaction=”https://tcc.taobao.com/cc/json/mobile_tel_segment.htm”method=”post”>请输入手机号:<inputtype=”tex…

    2022年5月10日
    39
  • 用Python打击盗号钓鱼网站

    用Python打击盗号钓鱼网站事情还要从我在吾爱看到的一个网址说起,放地址:http://tencent.outlook.com.eskdp.xyz/mail/打开之后是一个模仿QQ空间登陆的页面,然后你在账号密码框里输入任何东西,它都会跳转到QQ邮箱的页面(这里的QQ邮箱确实是腾讯旗下的QQ邮箱),这样会给很多小白造成错觉:嗯,一定是QQ家族出现了问题,我登陆QQ空间竟然给我跳到QQ邮箱了。我们来抓下包,在这个页面打开开发者工具(右键-检查),打开Network,因为后面会有跳转,所以勾选上Preservelog,然后随便输入

    2022年7月26日
    7
  • 使用adb命令安装apk到手机

    使用adb命令安装apk到手机第一步让真机与电脑相连,cmd打开dos命令窗口(打开cmd的快捷键是Windows+R).第二步输入adbdevices查看手机与电脑是否连接成功,能看到设备信息就代表设备已经连接成功了.第三步紧接着就可以安装apk了.首次要知道自己的apk放在哪个盘符的文件里了.比如我的apk放在E:\data里.进入apk文件所在的目录:输入…

    2022年6月7日
    750
  • idea2021激活码_最新在线免费激活

    (idea2021激活码)2021最新分享一个能用的的激活码出来,希望能帮到需要激活的朋友。目前这个是能用的,但是用的人多了之后也会失效,会不定时更新的,大家持续关注此网站~IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年3月26日
    47
  • PXE启动服务器及客户端镜像制作

    PXE启动服务器及客户端镜像制作基于CentOS6的PXE无盘系统制作,包含服务器端必要服务的设置开启,客户端镜像文件系统,根文件系统的制作,PXE选单的制作.

    2022年6月17日
    81

发表回复

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

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