我有一个带有NSMutableDictionaries
的NSMutableArrays列表,其中包含对象和键。像:
[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"]]];
}
}
感谢您的帮助。