0

This is the default contacts image

I want to implement for getting or loading 10 contacts at a time from address book.Any possibility to retrieve all contacts from address book but display them 10-10 contacts at a time.I am retrieving image,first name,last name of all iphone contacts.I want to implement this to email retrive email contacts also like 10-10 email contacts. Like this image the contacts or email contacts to be retrieved Here is my sample code:

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];

Any valuable suggestions will be appreciated....

Thanks in advance.

Vidhyanand
  • 993
  • 10
  • 21

1 Answers1

1

After getting all contacts in one array copy ten contacts to another array and cal table reload method with that new array by calling this method initially lowerlimit = 0 and 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];

}  

in table delagete method cellforrowatindex use this

    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];
    }
} 

here we increment lowerlimit and upperlimit in loadmorecells method

-(void)loadmorecells
    {

        lowerlimit = upperlimit;

        upperlimit = upperlimit +10;
        [self tabledataloadingmethod];
    }
ganesh manoj
  • 977
  • 10
  • 24