0

Hi guys I need your help in my situation, I am working with UISearchBar and all the delegate method I already declared, but I don't know the logic to reload the table data with filtered array.
All the data in my table come from json.

This is my code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 ChatListCell *cell=[tableView dequeueReusableCellWithIdentifier:@"contactListCell"];
 if(!cell){
     cell = [[ChatListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"contactListCell"];

 }
if (issearching) {
    ChatListData *chatlistdata = [filteredContentList objectAtIndex:indexPath.row];
}


NSLog(@"ceel %@", cell);
ChatListData *chatlistData = [chatList objectAtIndex:indexPath.row];
NSString *txtName = chatlistData.name;
NSLog(@"name %@", txtName);
NSData *emojiData = [txtName dataUsingEncoding:NSUTF8StringEncoding];
NSString *emojiTxtName = [[NSString alloc] initWithData:emojiData   encoding:NSNonLossyASCIIStringEncoding];
 cell.txtName.text = emojiTxtName;
 cell.txtTime.text = chatlistData.time;
 NSString *stringImg = @"image";
 NSString *stringVideo = @"video";
    if(![chatlistData.mime_type isEqual: [NSNull null]]){
    if ([chatlistData.mime_type rangeOfString:stringImg].location ==   NSNotFound || [chatlistData.mime_type rangeOfString:stringVideo].location == NSNotFound) {
            if ([chatlistData.mime_type rangeOfString:stringImg].location == NSNotFound) {
                cell.txtMsg.text = @"Image";
            }else if([chatlistData.mime_type rangeOfString:stringVideo].location == NSNotFound){
                cell.txtMsg.text = @"Video";
            }

This is my tabview code of cell index.

   -(void)searchBar:(UISearchBar*)searchBar textDidChange: (NSString*)text
 {
if(text.length == 0)
{
    issearching = FALSE;
}
else
{
    NSMutableArray *chatlitdata;
    issearching= true;
    NSLog(@"searching");
    filteredContentList = [[NSMutableArray alloc] init];
    filteredContentList = chatlitdata;


       // if(nameRange.location != NSNotFound || descriptionRange.location != NSNotFound)
        {
            [filteredContentList addObject:chatList];
        }

}
Fabio Berger
  • 1,921
  • 2
  • 24
  • 29
sandeep tomar
  • 303
  • 1
  • 5
  • 17
  • where you struck my bro... – Anbu.Karthik Dec 11 '15 at 12:28
  • Thanks sir for your response, i have a uitablview with contacts all the contacts are come from the server, now i am working with uisearchbar and i am declared all delegates method, but i don't know how will i reload table when i texting in uisearch bar. i need to search by the names of contacts. – sandeep tomar Dec 11 '15 at 12:31
  • simple , before see this link http://stackoverflow.com/questions/18719517/how-do-i-use-the-uisearchbar-and-uisearchdisplaycontroller, if you not get the answer reply here I will help you – Anbu.Karthik Dec 11 '15 at 12:35
  • add '[tableview reloadData]' in the end of 'searchBar textDidChange:' – vaibby Dec 11 '15 at 12:37
  • ok sir @Anbu.Karthik i tried to work on your link and i will back to you sir, i always thankful to you sir – sandeep tomar Dec 11 '15 at 12:42
  • thanx bro , simply say karthik don't say sir... – Anbu.Karthik Dec 11 '15 at 12:43
  • hi sir i am getting this error after crash the app when i text something in searchable :- "2015-12-16 10:43:49.064 Wazapper[571:18940] -[ChatListData compare:options:range:]: unrecognized selector sent to instance 0x7b943c60 2015-12-16 10:43:49.171 Wazapper[571:18940] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ChatListData compare:options:range:]: unrecognized selector sent to instance 0x7b943c60' " – sandeep tomar Dec 16 '15 at 05:05
  • hello sir i need your help, i am getting problem one of my situation. – sandeep tomar Dec 23 '15 at 07:16

0 Answers0