大家好我在我的情况下需要你的帮助,我正在使用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];
}
}