gpt4 book ai didi

iphone - 如何从地址簿中检索 10-10 个联系人

转载 作者:行者123 更新时间:2023-11-29 04:05:37 26 4
gpt4 key购买 nike

This is the default contacts image

我想实现一次从地址簿中获取或加载 10 个联系人。可以从地址簿中检索所有联系人,但一次显示 10-10 个联系人。我正在检索图像、名字、姓氏所有 iphone 联系人。我想实现此功能以通过电子邮件检索电子邮件联系人,也如 10-10 个电子邮件联系人。 Like this image the contacts or email contacts to be retrieved这是我的示例代码:

SData *imageData = (NSData *)CFBridgingRelease(ABPersonCopyImageDataWithFormat(ref, kABPersonImageFormatThumbnail)) ;

CFStringRef firstName1, lastName1;


firstName1 = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
lastName1 = ABRecordCopyValue(ref, kABPersonLastNameProperty);
NSString *name=[[NSString alloc]init];


if ([[NSString stringWithFormat:@"%@",firstName1] isEqualToString:@"(null)"] && [[NSString stringWithFormat:@"%@",lastName1] isEqualToString:@"(null)"])
{

name = @"No Name";
}
else if([[NSString stringWithFormat:@"%@",firstName1] isEqualToString:@"(null)"] && ![[NSString stringWithFormat:@"%@",lastName1] isEqualToString:@"(null)"])
{

name = [NSString stringWithFormat:@"%@",lastName1];
}

else
{
name = [NSString stringWithFormat:@"%@",firstName1];

}

name= [ name capitalizedString];

EmailandCotactsModel *emailmodel=[[EmailandCotactsModel alloc]init];
emailmodel.emailemailstring=(__bridge NSString *)(contno);
emailmodel.emailusernamestring=name;


if(!imageData)
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"NoImage" ofType:@"png"];
NSData *photoData = [NSData dataWithContentsOfFile:path];
emailmodel.emailimagesData=photoData;
}
else
{
emailmodel.emailimagesData=imageData;

}


[emailarray addObject:emailmodel];

callsmsDataBool=NO;

NSLog(@"table email count %d and i %d",emailarray.count,tablecountint);
if(emailarray.count==tablecountint)
{

NSLog(@"table email reload");

tablecountint=tablecountint+10;

dispatch_async( dispatch_get_global_queue(0,0),^{
[self reloadtable];
});

NSLog(@"perform selection in bg");

}

}
}


[self.tableview reloadData];


if(!emailarray.count && [socialstring isEqualToString:@"Email"])
{
selectedlabel.text=@"Emails not found";
}
else if(emailarray.count && [socialstring isEqualToString:@"Email"])
{
// selectedlabel.text=@"Email";

selectedlabel.text=[NSString stringWithFormat:@"%ld",nPeople];
}
else if(!emailarray.count && [socialstring isEqualToString:@"SMS"])
{
selectedlabel.text=@"Phone no's not found";
}
else if(emailarray.count && [socialstring isEqualToString:@"SMS"])
{
selectedlabel.text=@"SMS";
}
else
{
selectedlabel.text=@"";
}

[tableview reloadData];

任何宝贵的建议将不胜感激......

提前致谢。

最佳答案

获取一个数组中的所有联系人后,将十个联系人复制到另一个数组,并通过最初调用此方法来使用该新数组重新加载校准表方法 lowerlimit = 0 和 upperlimit=10;

-(void)tabledataloadingmethod
{
for (lowerlimit=0+lowerlimit; lowerlimit<upperlimit; lowerlimit++)
{
if (lowerlimit<[self.array1 count])
{
OBJECT *obj=[self.array1 objectAtIndex:lowerlimit];
[self.array2 addObject:obj];

}

}
[self.tbleview reloadData];

}

在表delagete方法cellforrowatindex中使用这个

    if ([self.array2 count]==indexPath.row)
{


UITableViewCell *cell1=[self.tbleview dequeueReusableCellWithIdentifier:@"cells"];
if(cell1==nil)
{
cell1=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Cells"];
}

cell1.textLabel.textColor = [UIColor whiteColor];
cell1.textLabel.text=@"Loading more...";

[self performSelector:@selector(loadmorecells) withObject:nil afterDelay:0.2];



return cell1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

if ([self.array2 count]>0 && ([self.array2 count]<[self.array1 count]))
{
return [self.array2 count]+1;
}
else
{
return [self.array2 count];
}
}

这里我们在 loadmorecells 方法中增加下限和上限

-(void)loadmorecells
{

lowerlimit = upperlimit;

upperlimit = upperlimit +10;
[self tabledataloadingmethod];
}

关于iphone - 如何从地址簿中检索 10-10 个联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15308162/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com