手机通讯录实现

手机通讯录实现

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


相关推荐

  • excel 堆积折线图_什么叫堆积折线图

    excel 堆积折线图_什么叫堆积折线图excel中关于折线图和堆积折现图的解释:“堆积折线图和带数据标记的堆积折线图堆积折线图用于显示每一数值所占大小随时间或有序类别而变化的趋势,可能显示数据点以表示单个数据值,也可能不显示这些数据点。如果有很多类别或者数值是近似的,则应该使用无数据点堆积折线图。提示为更好地显示此类型的数据,您可能要考虑改用堆积面积图。更通俗的解释为: 如果有两个数据系列,折线图中两个数据系列是独立…

    2022年4月20日
    145
  • 后台 管理 系统

    后台 管理 系统课程/视频管理系统:https://item.taobao.com/item.htm?spm=a2oq0.12575281.0.0.50111deb1nO3pa&ft=t&id=643539140484教务管理系统:https://item.taobao.com/item.htm?spm=a2oq0.12575281.0.0.50111deb1nO3pa&ft=t&id=643539140484成绩管理系统:https://item.taobao.com/item.h

    2022年4月25日
    41
  • linux常用命令vi 退出_vi怎么退出编辑模式

    linux常用命令vi 退出_vi怎么退出编辑模式Linux中vi、删除和退出简单操作

    2022年9月1日
    1
  • 心形线的图形_心形线公式

    心形线的图形_心形线公式心形线,是一个圆上的固定一点在它绕着与其相切且半径相同的另外一个圆周滚动时所形成的轨迹,因其形状像心形而得名。当然我觉得与其说它像心,还不如说它像屁股。相关软件参见:数学图形可视化工具,使用自己定义语

    2022年8月1日
    1
  • golang代理转发基础「建议收藏」

    golang代理转发基础「建议收藏」golang代理转发基础go标准库已经实现了一个反向代理工具,通过代理将客户端的请求转发到代理服务器。什么是反向代理?维基百科解释:”Incomputernetworks,areverseproxyisatypeofproxyserverthatretrievesresourcesonbehalfofaclientfromoneormore…

    2022年7月26日
    10
  • js实现的A星算法[通俗易懂]

    js实现的A星算法[通俗易懂]一、前言最近在写js的slg游戏,需要用到a星算法。之前用python写过https://blog.csdn.net/qq_39687901/article/details/80753433,现在再用js写一遍。二、源码//二维数组functionArray2D(w,h,num){vardata=[];vardefault_num=num|…

    2022年9月27日
    0

发表回复

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

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