我有一个带有对象和键的 NSMutableArrays 列表NSMutableDictionaries
。喜欢:
[silestoneArray addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Zen: Unsui", @"name",
@"silestone-unsui1.jpg", @"image", nil]];
我有一个有效的搜索,但我现在正试图继续查看详细信息。我需要找到一种从搜索结果中调用对象和键的方法,以便当我从搜索结果中分离时,传递正确的数据。
我的 didselectrowatindexpath 和 prepareforsegue 看起来像这样:
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView == self.mainTableView){
[self.detailViewController setDetailItem:[[contentsList objectAtIndex:indexPath.section]
objectAtIndex: indexPath.row]];}
else
[self.detailViewController setDetailItem:[[contentsList objectAtIndex:indexPath.section]
objectAtIndex: indexPath.row]];
}
#pragma mark - Segue
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"detailview"]) {
UIViewController *detailViewController = [segue destinationViewController];
// In order to manipulate the destination view controller, another check on which table (search or normal) is displayed is needed
if(sender == self.searchDisplayController.searchResultsTableView) {
detailViewController = self.detailViewController=segue.destinationViewController;
}
else {NSLog(@"Sender: %@", [sender class]);
self.detailViewController=segue.destinationViewController;
}
}
}
这将传递给一个详细视图,该视图调用数据,如下所示:
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
}
- (void)configureView
{
// Update the user interface for the detail item.
if (self.detailItem) {
self.navigationItem.title = [self.detailItem objectForKey:@"name"];
[self.detailImage setImage:[UIImage imageNamed:self.detailItem[@"image"]]];
}
}
我现在遇到的问题是,当我从结果中分离出来时,它会从我的原始表中发送结果,所以无论结果的单元格说什么,图像和标题都将与未过滤结果的顺序相对应。
我知道这是因为我在 didselectrow 中都调用了 contentsList,但是当我尝试搜索结果时它崩溃了。
错误报告是:-[__NSCFConstantString objectForKey:]: unrecognized selector sent to instance 0x21ed8
在豁免断点下,它表示此时正在抛出它:
self.navigationItem.title = [self.detailItem objectForKey:@"name"];
在详细视图的这一部分中:
- (void)configureView
{
// Update the user interface for the detail item.
if (self.detailItem) {
self.navigationItem.title = [self.detailItem objectForKey:@"name"];
[self.detailImage setImage:[UIImage imageNamed:self.detailItem[@"image"]]];
}
}
谢谢你的帮助。