如何在UISearchBar中应用逻辑来重新加载具有新数据的表?

时间:2015-12-11 12:26:56

标签: ios uitableview uisearchbar

大家好我在我的情况下需要你的帮助,我正在使用UISearchBar以及我已经声明的所有委托方法,但我不知道用过滤数组重新加载表数据的逻辑。
我表中的所有数据都来自json。

这是我的代码:

- (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";
            }

这是我的单元索引的tabview代码。

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

}

0 个答案:

没有答案