手机通讯录实现

手机通讯录实现

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


相关推荐

  • 微信小程序制作表格代码「建议收藏」

    微信小程序制作表格代码「建议收藏」微信小程序中没有专门的表格制作工具,不过使用列表渲染可以实现,下面是我做的表格图片:方法如下:在XXX.wxml中填写下面的代码参数内容{{item.code}}{{item.text}}{{item.type}}

    2022年7月27日
    41
  • Double 转 String

    Double 转 String场景Double整数部分超6位时用科学计数法表示,如123456789.50表示为1.234567895E8解决doubled=123456789.50;DecimalFormatformat=newDecimalFormat(&amp;amp;amp;amp;quot;#.00&amp;amp;amp;amp;quot;);Stringstr=format.format(d);System.out.println(str);…

    2022年10月24日
    0
  • java的单例模式是什么_Java单例模式是什么

    java的单例模式是什么_Java单例模式是什么Java单例模式是什么时间:2017-07-14来源:华清远见JAVA学院Java单例模式简介在GoF的23种设计模式中,单例模式是比较简单的一种。然而,有时候越是简单的东西越容易出现问题。下面就单例设计模式详细的探讨一下。所谓单例模式,简单来说,就是在整个应用中保证只有一个类的实例存在。就像是JavaWeb中的application,也就是提供了一个全局变量,用处相当广泛,比如保存全…

    2022年7月25日
    4
  • wpf滑动动画_旋转平移矩阵

    wpf滑动动画_旋转平移矩阵在WPF动画中常见的动画就平移、缩放以及旋转,一般会用到故事板(Storyboard)和浮点动画(DoubleAnimation),下面我们先对这两个进行具体的介绍,因为本次我们主要利用故事板来添加动画:一.Storyboard:俗称故事板,在VS中意思是,一个容器的时间线,该时间线为子动画提供对象和属性确定信息:其重要的两个方法`Storyboard.SetTarget();`绑定动画和`Storyboard.SetTargetProperty();`依赖的属性一般用法有:Storyboard

    2022年10月21日
    0
  • linux如何修改用户名_linux修改IP

    linux如何修改用户名_linux修改IP以下步骤都需要进入root权限操作suroot如果没有root权限,设置root密码sudopasswdrootsudovi/etc/passwd找到原先的用户名,将其改为自己的用户名sudovi/etc/shadow找到原先用户名(所有的名字都要改),改为自己的用户名将home目录下的用户目录改为自己的用户名:例如原先目录名为xxxx,现要改为用户yyyy。用命令mvxxxxyyyy即可。reboot重启即可发现用户名已经修

    2022年9月18日
    0
  • linux ettercap,CentOS下安装ettercap

    linux ettercap,CentOS下安装ettercapCentOS下安装ettercapettercap下载地址http://ettercap.sourceforge.net/download.php下载好之后解压出来,进入到解压目录#tarzxvfettercap-NG-0.7.3.tar.gz#cdettercap-NG-0.7.3阅读README#vimREADMEMANDATORY://安装必须依赖的libpcap>=…

    2022年6月28日
    32

发表回复

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

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