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