ठीक है, मैं मुझे मिल गया लगता है, यह एक हैक का एक सा की तरह लगता है लेकिन यह मेरी प्रयोजनों के लिए काम करता है:
मैं स्टोरीबोर्ड उपयोग कर रहा हूँ: मैं सीधे यह की चोटी पर UISearchBarDisplayController के साथ एक UITableView नियंत्रक की है। कोई कोड बस खींचें और छोड़ें। केवल मुझे मूल सरणी से एक सेल प्रदर्शित करते हैं, खोज सरणी के साथ नहीं दिया जाएगा:
वहाँ से, मैं इस ट्यूटोरियल खोज करने के लिए खोज पट्टी सही ढंग से http://clingingtoideas.blogspot.com/2010/02/uitableview-how-to-part-2-search.html
हालांकि prepareForSegue प्राप्त करने के लिए पीछा किया।
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (savedSearchTerm) {
searchRowSelected = indexPath.row; //<-- the trick that worked
[self performSegueWithIdentifier:@"ShowDetail" sender:self];
}
}
searchRowSelected किसी पूर्णांक चर है कि मैं वर्ग के शीर्ष पर घोषित है:
तो मैं didSelectRowAtIndexPath इस्तेमाल किया।
didSelectRowAtIndexPath: पता था कि मैं कौन सी पंक्ति का चयन कर रहा था, लेकिन तैयार करें ForSegue नहीं था। Thats क्यों मुझे उस चर की जरूरत है।
यह वह जगह है मैं यह कैसे 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];
}
साफ करने के लिए इस कोड का उपयोग मैं सभी कान हूँ :)
स्रोत
2012-02-17 19:58:13
/आपने कैसे तैयार किया है 'readyForSeque: प्रेषक:'? मैं कैसे के बारे में searchDisplayController.active वर्तमान tableview तय करने के लिए जाँच http://stackoverflow.com/questions/10033279/prepareforsegue-after-uisearchdisplaycontroller/19814031#19814031 – hop