- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"2.png"] style:UIBarButtonItemStyleBordered target:self action:nil];
self.navigationItem.rightBarButtonItem = btn;
self.navigationItem.title = @"Contacts";
sBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0,320,30)];
sBar.delegate = self;
[self.view addSubview:sBar];
sBar.placeholder=@"Search";
searchedData = [[NSMutableArray alloc]init];
tableData = [[NSMutableArray alloc]init];
[tableData addObjectsFromArray:dataSource];
}
Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中显示那些联系人时遇到问题,这些联系人位于我手机的地址簿中.
从谷歌联系人应用程序我发现了许多不同的版本,如何查询这些联系人:
不使用选择
Uri uri = ContactsContract.CONTACT.CONTENT_URI;
getActivity().getContentResolver().query(uri,PROJECTION, null, null, null);
Run Code Online (Sandbox Code Playgroud)仅使用具有可见组= = 1的联系人
Uri uri = ContactsContract.CONTACT.CONTENT_URI;
String selection = Contacts.IN_VISIBLE_GROUP + "=1"
getActivity().getContentResolver().query(uri,PROJECTION, selection, null, null);
Run Code Online (Sandbox Code Playgroud)或者使用目录查询参数
Uri uri = Contacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(Directory.DEFAULT)).build();
getActivity().getContentResolver().query(uri, PROJECTION, null, null, null);
Run Code Online (Sandbox Code Playgroud)最后一次提供最佳结果,但没有任何查询真正令人满意!:(我在不同的设备上测试了所有这些,但从来没有能够准确地获得电话簿中的联系人数量.
有人有一个想法,为什么没有查询适用于所有设备?
以下是我的测试结果:
================================================== ===============
| 设备\选择| 电话簿 | 不(1)| 可见组(2)| Directory.Default(3)|
================================================== ===============
| Galaxy S | 288 | 302 | 288 | …
我有一个这样的清单
一个人
Cperson
APerson2
BPerson
我希望它如此出现
一个
Aperson Aperson2
乙
Bperson
C
Cperson
我在这里发现了一篇解释它的帖子:http: //pmosd.blogspot.com/2013/07/headers-in-angularjs-ng-repeats.html
但作为一个Angular noob,我不知道在js文件中放置函数和过滤器的位置以及如何将其正确编码到我的html中.我试着关注我链接的帖子,但是我的无序列表中的联系人名称不会显示在浏览器中.这是我目前的JS和HTML文件.我曾尝试将过滤器和功能放在不同的地方,但这是我最近的尝试.
Directory.js:
'use strict';
var myApp = angular.module('myappname');
myApp.controller('DirectoryCtrl', function ($scope) {
$scope.contacts = [{
'fname': 'Randy',
'lname': 'Johnson',
'location': 'Seattle, WA'
}, {
'fname': 'Andy',
'lname': 'Pettite',
'location': 'Bronx, NY'
}, {
'fname': 'Jon',
'lname': 'Lester',
'location': 'Boston, MA'
}];
});
myApp.filter("headerChunk", function () {
return function (orig, same, getChunkID) {
if (!(orig instanceof Array)) return orig;
if (orig.length == 0) …
Run Code Online (Sandbox Code Playgroud) javascript contact-list angularjs angularjs-ng-repeat angularjs-filter
我能够从简单的html和javascript中获取并显示联系人照片,但是当我使用angularjs模型显示联系人照片时,我收到错误.以下是我的源代码:
列出我要显示联系人的位置:
<ul class="list">
<li class="item item-thumbnail-left" ng-repeat="contact in contactList">
<img ng-src="{{contact.mphoto}}"/> <!--When I put this path directly ( ie "content://com.android.contacts/contacts/30/photo"), I am able to display the image, but when I fetch it from the controller, I am getting error: "unable to read contacts from asset folder" -->
<h2>{{contact.name}}</h2>
<p >{{contact.number}}</p>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
这是我设置ContactList的控制器:
ContactService.find("").then(function(contacts) {
for (var i = 0; i < contacts.length; i++)
{
if (contacts[i].phoneNumbers !== null)
{
for (var j = 0; j < contacts[i].phoneNumbers.length; j++) …
Run Code Online (Sandbox Code Playgroud)