【发布时间】:2014-12-16 22:14:57
【问题描述】:
我有一个项目,在情节提要上创建了 tableView。这很简单,我正在按照教程进行操作,我的视图控制器看起来像这样
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
cell.textLabel.text = restaurantDisplayNames[indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}else{
cell.accessoryType = UITableViewCellAccessoryNone;
}
[tableView deselectRowAtIndexPath:indexPath animated:YES
];
}
因此,当您点击一个单元格时,它会在其旁边放置一个复选标记。现在我希望人们能够搜索事物。问题是,Apple 更改了 iOS 8 的搜索栏,据说让它更简单,但我在 UISearchController 上找不到任何教程,它取代了贬低的方法。
所以我拖放一个搜索栏和搜索显示控制器到我的视图控制器中,并添加了UISearchControllerDelegate, UISearchResultsUpdating> 协议声明,但我遇到了崩溃:
'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
每当我点击搜索栏时。
我也有方法
-(void)updateSearchResultsForSearchController:(UISearchController *)searchController{
}
但它是空的,因为我不知道该放什么。据说它非常简单,只需要几行代码就可以启动和运行,但我在这里找到的一个教程:http://www.stuartbreckenridge.com/blog/examining-the-new-uisearchcontroller-api 现在只是在 swift 中,但没有解释该方法中的内容。
【问题讨论】:
标签: cocoa-touch uisearchcontroller