は、[OK]を私はそれはハックのビットのように思える、私はそれを得たと思いますが、それは私の目的のために動作します:私は、ストーリーボードを使用しています
: は私が直接その上にUISearchBarDisplayControllerとのUITableViewコントローラを持っています。コードをドラッグ&ドロップするだけではありません。
そこから、私が正しくhttp://clingingtoideas.blogspot.com/2010/02/uitableview-how-to-part-2-search.html
を検索する検索バーを取得するには、このチュートリアルに従っしかしprepareForSegueは:私だけは元の配列からではなく、検索配列でセルを表示できます。
だから私はdidSelectRowAtIndexPathを使用:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (savedSearchTerm) {
searchRowSelected = indexPath.row; //<-- the trick that worked
[self performSegueWithIdentifier:@"ShowDetail" sender:self];
}
}
searchRowSelectedは、私はクラスの先頭で宣言int型の変数です。
didSelectRowAtIndexPath:私が選択していた行を知っていましたが、prepareForSegueは選択していませんでした。なぜ私はその変数が必要なのですか?
これは私がprepareForSegueでそれを使用する方法である:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"ShowDetail"]) {
dvc = [segue destinationViewController];
NSIndexPath* path = [self.tableView indexPathForSelectedRow];
int row = [path row];
if (savedSearchTerm){ //set the detailViewController with the searched data cell
myDataClass* c = [searchResults objectAtIndex:searchRowSelected];
dvc.myDataClass = c;
}else{ //set the detailViewController with the original data cell
myDataClass* c = [array objectAtIndex:row];
dvc.myDataClass = c;
}
}
}
またクリーンアップするために、このコードを使用しsavedSearchTerm
-(void) searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller{
[self setSavedSearchTerm:nil];
}
誰もがよりよい解決策を持っている場合、私はすべての耳だ:)
/how /あなたは 'prepareForSeque:sender:'を実装しましたか?私は単純な実装について説明しました。http://stackoverflow.com/questions/10033279/prepareforsegue-after-uisearchdisplaycontroller/19814031#19814031 – hop