背景iOS 5的搜索显示控制器和的UITableViewController
的重用我有一个iPhone应用程序,通过子每次使用再分级利用了UITableViewController
子类的几个地方。其中一种用途是搜索控制器。
@interface TableViewController : UITableViewController
// ...
@interface SearchTableViewController : TableViewController <UISearchDisplayDelegate, UISearchBarDelegate>
在故事板编辑我在,使得使用的TableViewController
每个视图相同的表视图,细胞结构,和重用标识符。到处都是我使用的故事板根据我的设计时间原型生成单元格,因此在tableView:cellForRowAtIndexPath:
方法中我不必包含if (cell == nil)
部分。
问题
我做错了什么,而不是由其他人一样的故事板产生我的搜索控制器的细胞。起初,我在if (cell == nil)
位中添加了一个来解决这个问题,但它会导致我的搜索显示空行。实际上,搜索会显示正确的空白行数。取消搜索后,结果将从背景中出现。下面是TableViewController
代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
ModelObject* obj = [self.dataSource modelAtIndex:indexPath.row];
UILabel* name = (UILabel*) [cell viewWithTag:1];
name.text = obj.name;
return cell;
}
我怀疑有可能是必要的,以确定问题的其他细节,但是,什么样的事情可能会导致这将是有帮助的任何提示。谢谢。