我有一个包含自定义单元格的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“
的“事件”类:
@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后,自定义单元格显示良好。但如果我使用搜索栏:
- 如果与递减属性等于“富”一个事件,如果我在搜索栏进入“酒吧”,我得到“没有结果”消息。这是正常的。
- 如果与desc的事件属性等于“富”,如果我在搜索栏输入“富”,细胞被显示,但不其内容!我只看到单元格的边框,并且lblDate和lblAuteur等于零。
为什么我这种行为?非常感谢您的帮助......我确定filteredArray和notFilteredArray正确填充(我多次检查过)。这意味着搜索机制运行良好。
我已经完成了**“搜索显示控制器”**和**“文件所有者**”之间的Interface Builder链接。无论如何,我试图把这两行放入viewDidLoad方法,但问题仍然存在... –