问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

(Object-C)iOS编程,类似于通讯录的项目

发布网友 发布时间:2022-04-23 02:38

我来回答

2个回答

懂视网 时间:2022-04-23 06:59

这次给大家带来右侧带索引通讯录实现(附代码),右侧带索引通讯录实现的注意事项有哪些,下面就是实战案例,一起来看一下。

通过jquery.charfirst.pinyin.js实现点击字母自动定位。实现动态加载通讯录数据。

主要代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
 <meta name="apple-mobile-web-app-capable" content="yes">
 <meta name="apple-mobile-web-app-status-bar-style" content="black">
 <meta name="format-detection" content="telephone=no">
 <title>通讯录首字母检索</title>
 <link rel="stylesheet" href="css/style.css" rel="external nofollow" >
</head>
<body>
 <header class="fixed">
 <p class="header">
 通讯录
 </p>
 </header>
 <p id="letter" ></p>
 <p class="sort_box">
 <p class="sort_list">
 <p class="num_logo">
 <img src="./img/img.png" alt="">
 </p>
 <p class="num_name">张三</p>
 </p>
 <p class="sort_list">
 <p class="num_logo">
 <img src="./img/img.png" alt="">
 </p>
 <p class="num_name">李四</p>
 </p>
 <p class="sort_list">
 <p class="num_logo">
 <img src="./img/img.png" alt="">
 </p>
 <p class="num_name">王五</p>
 </p>
 <p class="sort_list">
 <p class="num_logo">
 <img src="./img/img.png" alt="">
 </p>
 <p class="num_name">刘六</p>
 </p>
 <p class="sort_list">
 <p class="num_logo">
 <img src="./img/img.png" alt="">
 </p>
 <p class="num_name">马七</p>
 </p>
 <p class="sort_list">
 <p class="num_logo">
 <img src="./img/img.png" alt="">
 </p>
 <p class="num_name">黄八</p>
 </p>
 <p class="sort_list">
 <p class="num_logo">
 <img src="./img/img.png" alt="">
 </p>
 <p class="num_name">莫九</p>
 </p>
 <p class="sort_list">
 <p class="num_logo">
 <img src="./img/img.png" alt="">
 </p>
 <p class="num_name">陈十</p>
 </p>
 <p class="sort_list">
 <p class="num_logo">
 <img src="./img/img.png" alt="">
 </p>
 <p class="num_name">a九</p>
 </p>
 <p class="sort_list">
 <p class="num_logo">
 <img src="./img/img.png" alt="">
 </p>
 <p class="num_name">1十</p>
 </p>
 <p class="sort_list">
 <p class="num_logo">
 <img src="./img/img.png" alt="">
 </p>
 <p class="num_name">黄八</p>
 </p>
 <p class="sort_list">
 <p class="num_logo">
 <img src="./img/img.png" alt="">
 </p>
 <p class="num_name">今天</p>
 </p>
 <p class="sort_list">
 <p class="num_logo">
 <img src="./img/img.png" alt="">
 </p>
 <p class="num_name">突然</p>
 </p>
 <p class="sort_list">
 <p class="num_logo">
 <img src="./img/img.png" alt="">
 </p>
 <p class="num_name">梵蒂冈</p>
 </p>
 <p class="sort_list">
 <p class="num_logo">
 <img src="./img/img.png" alt="">
 </p>
 <p class="num_name">快乐的</p>
 </p>
 <p class="sort_list">
 <p class="num_logo">
 <img src="./img/img.png" alt="">
 </p>
 <p class="num_name">撒地方</p>
 </p>
 <p class="sort_list">
 <p class="num_logo">
 <img src="./img/img.png" alt="">
 </p>
 <p class="num_name">官方</p>
 </p>
 <p class="sort_list">
 <p class="num_logo">
 <img src="./img/img.png" alt="">
 </p>
 <p class="num_name">哦</p>
 </p>
 <p class="sort_list">
 <p class="num_logo">
 <img src="./img/img.png" alt="">
 </p>
 <p class="num_name">分割</p>
 </p>
 <p class="sort_list">
 <p class="num_logo">
 <img src="./img/img.png" alt="">
 </p>
 <p class="num_name">票</p>
 </p>
 </p>
 <p class="initials">
 <ul>
 <li><img src="./img/068.png"></li>
 </ul>
 </p>
 <script type="text/javascript" src="http://cdn.bootcss.com/jquery/2.2.3/jquery.min.js"></script>
 <script type="text/javascript" src="js/jquery.charfirst.pinyin.js"></script>
 <script type="text/javascript" src="js/sort.js"></script>
</body>
</html>

style.css

html,body,p,ul,li,ol,a,input,textarea,p,dl,dt,dd{margin:0;padding:0;}
ul li{list-style: none;}
a{text-decoration: none;cursor: pointer;}
html{height: 100%;}
body{height: 100%;background: #f5f5f5;position: relative;font-family: '微软雅黑';max-width: 640px;margin:auto;}
a,input,img,textarea,span,p{outline: 0;-webkit-tap-highlight-color:rgba(255,0,0,0);}
header{
 width:100%;
 height: 45px;
 background: #ececea;
 border-bottom: 1px solid #ddd;
}
header.fixed{
 position: fixed;
 left: 0;
 top: 0;
 z-index: 99;
}
.header{
 margin:0 20px;
 text-align: center;
 color: #4e4a49;
 font-size: 1em;
 height: 45px;
 line-height: 45px;
 position: relative;
}
#letter{
 width: 100px;
 height: 100px;
 border-radius: 5px;
 font-size: 75px;
 color: #555;
 text-align: center;
 line-height: 100px;
 background: rgba(145,145,145,0.6);
 position: fixed;
 left: 50%;
 top: 50%;
 margin:-50px 0px 0px -50px;
 z-index: 99;
 display: none;
}
#letter img{
 width: 50px;
 height: 50px;
 float: left;
 margin:25px 0px 0px 25px;
}
.sort_box{
 width: 100%;
 padding-top: 45px;
 overflow: hidden;
}
.sort_list{
 padding:10px 60px 10px 80px;
 position: relative;
 height: 40px;
 line-height: 40px;
 border-bottom:1px solid #ddd;
}
.sort_list .num_logo{
 width: 50px;
 height: 50px;
 border-radius: 10px;
 overflow: hidden;
 position: absolute;
 top: 5px;
 left: 20px;
}
.sort_list .num_logo img{
 width: 50px;
 height: 50px;
}
.sort_list .num_name{
 color: #000;
}
.sort_letter{
 background-color: white;
 height: 30px;
 line-height: 30px;
 padding-left: 20px;
 color:#787878;
 font-size: 14px;
 border-bottom:1px solid #ddd;
}
.initials{
 position: fixed;
 top: 47px;
 right: 0px;
 height: 100%;
 width: 15px;
 padding-right: 10px;
 text-align: center;
 font-size: 12px;
 z-index: 99;
 background: rgba(145,145,145,0);
}
.initials li img{
 width: 14px;
}

sort.js

$(function(){
 var Initials=$('.initials');
 var LetterBox=$('#letter');
 Initials.find('ul').append('<li>A</li><li>B</li><li>C</li><li>D</li><li>E</li><li>F</li><li>G</li><li>H</li><li>I</li><li>J</li><li>K</li><li>L</li><li>M</li><li>N</li><li>O</li><li>P</li><li>Q</li><li>R</li><li>S</li><li>T</li><li>U</li><li>V</li><li>W</li><li>X</li><li>Y</li><li>Z</li><li>#</li>');
 initials();
 $(".initials ul li").click(function(){
 var _this=$(this);
 var LetterHtml=_this.html();
 LetterBox.html(LetterHtml).fadeIn();
 Initials.css('background','rgba(145,145,145,0.6)');
 setTimeout(function(){
 Initials.css('background','rgba(145,145,145,0)');
 LetterBox.fadeOut();
 },1000);
 var _index = _this.index()
 if(_index==0){
 $('html,body').animate({scrollTop: '0px'}, 300);//点击第一个滚到顶部
 }else if(_index==27){
 var DefaultTop=$('#default').position().top;
 $('html,body').animate({scrollTop: DefaultTop+'px'}, 300);//点击最后一个滚到#号
 }else{
 var letter = _this.text();
 if($('#'+letter).length>0){
  var LetterTop = $('#'+letter).position().top;
  $('html,body').animate({scrollTop: LetterTop-45+'px'}, 300);
 }
 }
 })
 var windowHeight=$(window).height();
 var InitHeight=windowHeight-45;
 Initials.height(InitHeight);
 var LiHeight=InitHeight/28;
 Initials.find('li').height(LiHeight);
})
function initials() {//排序
 var SortList=$(".sort_list");
 var SortBox=$(".sort_box");
 SortList.sort(asc_sort).appendTo('.sort_box');//按首字母排序
 function asc_sort(a, b) {
 return makePy($(b).find('.num_name').text().charAt(0))[0].toUpperCase() < makePy($(a).find('.num_name').text().charAt(0))[0].toUpperCase() ? 1 : -1;
 }
 var initials = [];
 var num=0;
 SortList.each(function(i) {
 var initial = makePy($(this).find('.num_name').text().charAt(0))[0].toUpperCase();
 if(initial>='A'&&initial<='Z'){
 if (initials.indexOf(initial) === -1)
 initials.push(initial);
 }else{
 num++;
 }
 });
 $.each(initials, function(index, value) {//添加首字母标签
 SortBox.append('<p class="sort_letter" id="'+ value +'">' + value + '</p>');
 });
 if(num!=0){SortBox.append('<p class="sort_letter" id="default">#</p>');}
 for (var i =0;i<SortList.length;i++) {//插入到对应的首字母后面
 var letter=makePy(SortList.eq(i).find('.num_name').text().charAt(0))[0].toUpperCase();
 switch(letter){
 case "A":
 $('#A').after(SortList.eq(i));
 break;
 case "B":
 $('#B').after(SortList.eq(i));
 break;
 case "C":
 $('#C').after(SortList.eq(i));
 break;
 case "D":
 $('#D').after(SortList.eq(i));
 break;
 case "E":
 $('#E').after(SortList.eq(i));
 break;
 case "F":
 $('#F').after(SortList.eq(i));
 break;
 case "G":
 $('#G').after(SortList.eq(i));
 break;
 case "H":
 $('#H').after(SortList.eq(i));
 break;
 case "I":
 $('#I').after(SortList.eq(i));
 break;
 case "J":
 $('#J').after(SortList.eq(i));
 break;
 case "K":
 $('#K').after(SortList.eq(i));
 break;
 case "L":
 $('#L').after(SortList.eq(i));
 break;
 case "M":
 $('#M').after(SortList.eq(i));
 break;
 case "N":
 $('#N').after(SortList.eq(i));
 break;
 case "O":
 $('#O').after(SortList.eq(i));
 break;
 case "P":
 $('#P').after(SortList.eq(i));
 break;
 case "Q":
 $('#Q').after(SortList.eq(i));
 break;
 case "R":
 $('#R').after(SortList.eq(i));
 break;
 case "S":
 $('#S').after(SortList.eq(i));
 break;
 case "T":
 $('#T').after(SortList.eq(i));
 break;
 case "U":
 $('#U').after(SortList.eq(i));
 break;
 case "V":
 $('#V').after(SortList.eq(i));
 break;
 case "W":
 $('#W').after(SortList.eq(i));
 break;
 case "X":
 $('#X').after(SortList.eq(i));
 break;
 case "Y":
 $('#Y').after(SortList.eq(i));
 break;
 case "Z":
 $('#Z').after(SortList.eq(i));
 break;
 default:
 $('#default').after(SortList.eq(i));
 break;
 }
 };
}

最终效果:

相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!

推荐阅读:

分享页面后跳转回首页

Vue自定义动态组件使用详解

热心网友 时间:2022-04-23 04:07

你既然已经把这个((联系人的字典)的数组)都已经拿到了    那么现在进行下面的步骤:

新建一个字典,并且给这个字典加入24个键值对,键值对的Key分别是 @"A",@"B",@"C"……@"Z",每一个键值对的Object都是一个 NSMutableArray 并且是初始化好了的NSMutableArray

遍历你之前得到的这个(联系人的字典)的数组,依据首字母,分别把联系人放到字典(1步骤)内的对应的数组上,

现在你得到了一个   具有24个Key的字典    并且这每一个Key对应的是一个数组,你之后在设置你的UITableView的时候比较方便

具体的方式就这样,有什么不明白的你可以QQ联系我,这儿我不是来的太频繁,429801517

下面是我花了一会写的个范例代码,你看看吧

- (void)viewDidLoad {
    [super viewDidLoad];
    NSMutableDictionary *dic = [self BuildDictionary];
    NSLog(@"%@",dic);
}

-(NSMutableDictionary *)BuildDictionary
{//这个函数返回的就是我们最终需要的了
    NSMutableArray * arr = [self BuildPeopleCard];
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    char a = 'A';
    do{
        [dic setObject:[[NSMutableArray alloc] init] forKey:[NSString stringWithFormat:@"%c",a]];
        a++;
    }while (a <= 'Z');
    for (NSString *str in arr)
    {
        char c = [str characterAtIndex:0];
        if (c >= 'a' && c<= 'z')
        {//对于你来说这儿也非必须
            c = c - 'a' + 'A';
        }
        NSString *LastStr = [NSString stringWithFormat:@"%c%@",c,[str substringFromIndex:1]];
        [dic[[NSString stringWithFormat:@"%c",c]] addObject:LastStr];
    }
    return dic;
}

-(NSMutableArray *)BuildPeopleCard
{//这个函数只是用于生成一个数组而已,对于你来说这个函数是不必的,因为你已经从服务器拿到了这个数组了
    NSMutableArray *PeopleCard = [[NSMutableArray alloc]init];
    NSMutableString *str = [NSMutableString stringWithString:@"Occasionally, Dad would get out his mandolin and play for the family. We three children: Trisha, Monte and I, George Jr., would often sing along. Songs such as the Tennessee Waltz, Harbor Lights and around Christmas time, the well-known rendition of Silver Bells. Silver Bells, Silver Bells, its Christmas time in the city would ring throughout the house. One of Dad's favorite hymns was The Old Rugged Cross. We learned the words to the hymn when we were very young, and would sing it with Dad when he would play and sing. Another song that was often shared in our house was a song that accompanied the Walt Disney series: Davey Crockett. Dad only had to hear the song twice before he learned it well enough to play it. Davey, Davey Crockett, King of the Wild Frontier was a favorite song for the family. He knew we enjoyed the song and the program and would often get out the mandolin after the program was over. I could never get over how he could play the songs so well after only hearing them a few times. I loved to sing, but I never learned how to play the mandolin. This is something I regret to this day. "];
    while (str.length > 1)
    {
        [PeopleCard addObject:[str substringToIndex:[str rangeOfString:@" "].location]];
        [str deleteCharactersInRange:NSMakeRange(0, [str rangeOfString:@" "].location + 1)];
    }
    return PeopleCard;
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
结核病是什么样的疾病? 曹丕17岁得了肺痨,明知自己命不长久,还要强争王位,是不是很自私呢?_百... 古代小说常出现的病名 急求一篇"生活小窍门"(500字)的作文 至今最有什么小妙招 健康的戒烟方法 笔记本电池锁死是什么原因引起的? 黑龙江债权转让合同纠纷该怎样取证 安徽债权转让合同纠纷应该怎么样取证 房产官司律师费多少 win7 系统如何把mov转为mp4 谁有友善福? 黑龙江省律师事务所 android 右侧字母索引用什么做最好 律所所长怎么称呼 下列与成语“望梅止渴”相同的反射是(  ) A.缩手反射 B.谈虎色变 C.老马识途 D.蜘蛛织 像望梅止渴成语 望梅止渴的同义词成语是什么 望梅止渴相近的网络成语 和望梅止渴相近的成语 望梅止渴思相近的成语 论文的文献综述右上角的符号怎么打 我和老公的弟媳妇不怎么说话 婆婆叫她带我去看病 我不想欠她人情 应该回答她? 我与媳妇弟弟媳妇的关系叫什么? 我和一个强势的弟媳相处咋办 我该怎么和弟媳妇相处? 和弟媳妇吵架了 有4年没有说话了,你们觉得应该是我先和她说话,还是她应该和我先说话 我是她嫂子, 爱情中的两个人男友让你听人间这首歌什么意思? 我与弟媳的社会关系 路过人间这首歌表达什么意思? 想脸上长颗痣有什么办法吗? 本人姓陈,带有火字旁和曰字旁的男孩子名字请问有比较好听的? 怎么才能在脸上弄颗痣,前面有看到说烫。。。 姓陈 男孩 想取个火字旁的名字2013年出生 姓陈,孔字辈,后面带火字旁的名字 姓陈带火字旁男孩名字有好听的吗? 陈姓火字旁男孩名字 男孩,父亲姓陈,需名火字旁的姓名,名叫什么好?谢谢! 含火字旁的男孩名字 姓陈 三个字 有寓意 我姓陈,想帮我儿子找个带火字旁的男孩名字最好两个的。 姓陈的男孩,带火字旁的什么取好,谢谢 求,带火字旁的男孩名字,姓陈,要好听顺耳的! 姓陈的男孩名字属马单字带火字旁 求一关于通讯录管理程序的源程序代码 河北省专接本满分是多少 河北2010专接本计算机专业都考哪些科目? 河北专接本计算机科目考几科 河北专接本计算机专业的专业科目考哪本书,要怎么学?看什么书?求指点 卧室怎样搭配软装?卧室软装搭配技巧 家庭装修时候,软装色彩搭配技巧是什么?