首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何从通讯录中检索10-10个联系人

如何从通讯录中检索10-10个联系人
EN

Stack Overflow用户
提问于 2013-03-09 14:54:45
回答 1查看 215关注 0票数 0

我想实现获取或加载10联系人从地址book.Any的可能性检索所有联系人从地址簿,但显示他们在同一时间10-10联系人我正在检索图像,名字,所有苹果手机联系人的姓氏。我想实现这一点,电子邮件检索电子邮件联系人也像10-10电子邮件联系人。

下面是我的示例代码:

代码语言:javascript
运行
复制
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];

任何有价值的建议都将不胜感激……

提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-09 15:10:39

在获得一个数组中的所有触点后,将10个触点复制到另一个数组中,并通过最初调用该方法lowerlimit =0和upperlimit=10调用具有新数组的表重新加载方法;

代码语言:javascript
运行
复制
-(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];

}  

在table delagete方法cellforrowatindex中,使用这个

代码语言:javascript
运行
复制
    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方法中增加下限和上限。

代码语言:javascript
运行
复制
-(void)loadmorecells
    {

        lowerlimit = upperlimit;

        upperlimit = upperlimit +10;
        [self tabledataloadingmethod];
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15308162

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档