我有一个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
取代 deprecated 方法的教程。
所以我将搜索栏和搜索显示控制器拖放到我的视图控制器中并添加了协议声明,但我遇到了崩溃:UISearchControllerDelegate, UISearchResultsUpdating>
'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
每当我点击搜索栏时。
我也有方法
-(void)updateSearchResultsForSearchController:(UISearchController *)searchController{
}
但它是空的,因为我不知道该放什么。据说它非常简单,只需要几行代码即可启动并运行,但我在这里找到的一个教程:http: //www.stuartbreckenridge.com/blog/examineing-the-new-uisearchcontroller-api现在只有在 swift 中,但没有解释该方法中的内容。