2013-12-11 141 views
0
  • 我有一个包含自定义单元格的UITableView。一切正常。但之后,我决定添加一个searchBar以便...搜索!包含自定义单元格的UITableView的UISearchBar =>空白单元格

  • 所以,我从增加了“搜索栏和搜索显示控制器”“对象库”我在厦门国际银行文件,该UITableView的下。

  • 我创建的自定义单元格的特定类:

    “CustomCell.h”

    @class CustomCell; 
    
    @interface CustomCell : UITableViewCell 
    { 
    } 
    
    @property (weak, nonatomic) IBOutlet UILabel *lblDate; 
    @property (weak, nonatomic) IBOutlet UILabel *lblAuteur; 
    
    @end 
    

    “CustomCell.m”

    no interesting stuff 
    

    “CustomCell .xib“

    enter image description here

  • “事件”类:

    @interface Event : NSObject 
    { 
    } 
    
    @property (strong, nonatomic) NSString *desc; 
    @property (strong, nonatomic) NSString *dateCreation; 
    
    @end 
    
  • 和包含的UITableView的UISearchBar的观点:

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
        static NSString *cellIdentifier = @"cell"; 
    
        // Determinate the current event 
        Event *currentEvent; 
        if (tableView == self.searchDisplayController.searchResultsTableView) 
         currentEvent = [filteredArray objectAtIndex:indexPath.row]; 
        else 
         currentEvent = [notFilteredArray objectAtIndex:indexPath.row]; 
    
        CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
    
        if(cell == nil) 
         cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
    
        cell.lblAuteur.text = [currentEvenement desc]; 
        cell.lblDate.text = [currentEvenement dateCreation]; 
    
        return cell; 
    } 
    
  • 好了,现在我们可以ñ来到我的问题。加载tableView后,自定义单元格显示良好。但如果我使用搜索栏

    1. 如果与递减属性等于“富”一个事件,如果我在搜索栏进入“酒吧”,我得到“没有结果”消息。这是正常的。
    2. 如果与desc的事件属性等于“富”,如果我在搜索栏输入“富”,细胞被显示,但不其内容!我只看到单元格的边框,并且lblDatelblAuteur等于

为什么我这种行为?非常感谢您的帮助......我确定filteredArraynotFilteredArray正确填充(我多次检查过)。这意味着搜索机制运行良好。

回答

0

对不起,人们寻找到解决这个问题......我 无法修复它,与总承包人不想要这个功能了,所以我放弃了。

0

检查这些设置,如果没有

self.searchDisplayController.searchResultsDelegate =自我; self.searchDisplayController.searchResultsDataSource = self;

试试这个,

+0

我已经完成了**“搜索显示控制器”**和**“文件所有者**”之间的Interface Builder链接。无论如何,我试图把这两行放入viewDidLoad方法,但问题仍然存在... –

7

经过多次“搜索”(双关)后,我发现问题。

当您使用原型单元格引用tableview时,不能依赖传入的tableview,因为有时该tableview是没有原型单元格的搜索tableview。

所以不是...

HomeTabCell *cell = (HomeTabCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

代替上面直接连接到表视图与原型细胞

HomeTabCell *cell = (HomeTabCell *)[self.HomeTableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

希望这有助于“实现代码如下”!

+0

感谢您的回答。如果我再次需要这个功能,我会让你联系。 –

+0

很好,这个工作... – ATOzTOA