0

현재 검색 디스플레이 컨트롤러를 세부보기로 세우려고하는데 행운이별로 없습니다! 검색 작업 및 제목 및 이미지 seguing mainTableView (원래 테이블보기) 있지만 searchdisplaytableview에서 segue 시도 할 때 충돌이 발생합니다.- [__ NSCFConstantString objectForKey :] : 인식 할 수없는 선택기가 인스턴스 0x21eb4로 전송되었습니다.

self.navigationItem.title = [self.detailItem objectForKey:@"name"]; 

상세 뷰의 전체 코드는 다음과 같습니다 : .H

#import <UIKit/UIKit.h> 

@interface SearchDetailViewController : UIViewController<UISplitViewControllerDelegate> 


@property (strong, nonatomic) id detailItem; 

@property (strong, nonatomic) IBOutlet UIImageView *detailImage; 

@end 

하는 .m

#import "SearchDetailViewController.h" 

@interface SearchDetailViewController() 

@end 

@implementation SearchDetailViewController 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (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"]]]; 
    } 
} 


- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 

은이 단계에서 상세 뷰에서 충돌한다 검색 코드는 .h

입니다. 16,
#import <UIKit/UIKit.h> 

@class SearchDetailViewController; 

@interface SearchWillWorkViewController : UIViewController<UITableViewDataSource, UITableViewDelegate, UISearchDisplayDelegate, UISearchBarDelegate> 
{ 
    NSMutableArray *graniteArray; 
    NSMutableArray *marbleArray; 
    NSMutableArray *quartzArray; 
    NSMutableArray *silestoneArray; 
    NSArray *searchRowSelected; 

    NSMutableArray *sectionArray; 

    UITableView *mainTableView; 

    NSMutableArray *contentsList; 
    NSMutableArray *searchResults; 
    NSString *savedSearchTerm; 

} 

@property (strong, nonatomic) SearchDetailViewController *detailViewController; 

@property (nonatomic, strong) IBOutlet UITableView *mainTableView; 
@property (nonatomic, strong) NSMutableArray *contentsList; 
@property (nonatomic, strong) NSMutableArray *searchResults; 
@property (nonatomic, copy) NSString *savedSearchTerm; 
@property (strong, nonatomic) NSArray *stoneSections; 


- (void)handleSearchForTerm:(NSString *)searchTerm; 
- (void)createStoneData; 


@end 

하는 .m

#import "SearchWillWorkViewController.h" 
#import "SearchDetailViewController.h" 

@interface SearchWillWorkViewController() 

@end 

@implementation SearchWillWorkViewController 

@synthesize mainTableView; 
@synthesize contentsList; 
@synthesize searchResults; 
@synthesize savedSearchTerm; 
@synthesize stoneSections; 
@synthesize detailViewController = _detailViewController; 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 

    // Save the state of the search UI so that it can be restored if the view is re-created. 
    [self setSavedSearchTerm:[[[self searchDisplayController] searchBar] text]]; 

    [self setSearchResults:nil]; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self createStoneData]; 

    // Restore search term 
    if ([self savedSearchTerm]) 
    { 
     [[[self searchDisplayController] searchBar] setText:[self savedSearchTerm]]; 
    } 
} 

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 

    [[self mainTableView] reloadData]; 
} 

- (void)createStoneData { 

    self.stoneSections=[[NSArray alloc] initWithObjects: 
         @"Granite",@"Marble",@"Quartz",@"Silestone",nil]; 

    graniteArray = [[NSMutableArray alloc] init]; 
    marbleArray = [[NSMutableArray alloc] init]; 
    quartzArray = [[NSMutableArray alloc] init]; 
    silestoneArray = [[NSMutableArray alloc] init]; 

    [graniteArray addObject:[[NSMutableDictionary alloc] 
          initWithObjectsAndKeys:@"Angel Cream", @"name", 
          @"angel-cream.jpg", @"image", nil]]; 

    [marbleArray addObject:[[NSMutableDictionary alloc] 
          initWithObjectsAndKeys:@"Arabescato", @"name", 
          @"arabescato.jpg", @"image", nil]]; 

    [quartzArray addObject:[[NSMutableDictionary alloc] 
          initWithObjectsAndKeys:@"Caesarstone: Black Knight", @"name", 
          @"Black Knight.jpg", @"image", nil]]; 

    [silestoneArray addObject:[[NSMutableDictionary alloc] 
           initWithObjectsAndKeys:@"Cielo: Aluminio Nube", @"name", 
           @"silestone-aluminio-nube.jpg", @"image", nil]]; 

    NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:graniteArray,marbleArray,quartzArray,silestoneArray, nil]; 
    [self setContentsList:array]; 

} 

/* 
// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Return YES for supported orientations 
return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 
*/ 

- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

- (void)handleSearchForTerm:(NSString *)searchTerm 
{ 
    [self setSavedSearchTerm:searchTerm]; 

    if ([self searchResults] == nil) 
    { 
     NSMutableArray *array = [[NSMutableArray alloc] init]; 
     [self setSearchResults:array]; 
    } 

    [[self searchResults] removeAllObjects]; 

    if ([[self savedSearchTerm] length] != 0) 
    { 
     for (NSMutableArray *array in contentsList) 
     { 
      for (NSDictionary* dictionary in array) 
      { 
       NSString *currentstring = [dictionary objectForKey:@"name"]; 
       NSRange r = [currentstring rangeOfString:searchTerm options:NSCaseInsensitiveSearch]; 
       if (r.location != NSNotFound) { 
        [[self searchResults] addObject:currentstring]; 
       } 
      } 
     } 
    } 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    // Return the number of sections. 
    if (tableView == [[self searchDisplayController] searchResultsTableView]) 
     return 1; 
    else 
     return [self.stoneSections count]; 
} 

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    if (tableView == [[self searchDisplayController] searchResultsTableView]) 
     return nil; 
    else 
     return [self.stoneSections objectAtIndex:section]; 
} 

#pragma mark - 
#pragma mark UITableViewDataSource Methods 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    NSInteger rows; 

    if (tableView == [[self searchDisplayController] searchResultsTableView]) 
     rows = [[self searchResults] count]; 
    else 
     rows = [[self.contentsList objectAtIndex:section] count]; 


    return rows; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"stoneCell"; 

UITableViewCell *cell = (UITableViewCell *)[mainTableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    NSString *contentForThisRow = nil; 

    if (tableView == [[self searchDisplayController] searchResultsTableView]) 
     contentForThisRow = [self.searchResults objectAtIndex:indexPath.row]; 
    else 
     contentForThisRow = [[[[self contentsList] objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"name"]; 

    cell.textLabel.text = contentForThisRow; 

    return cell; 
} 

#pragma mark - 
#pragma mark UITableViewDelegate Methods 

- (void)tableView:(UITableView *)tableView 
didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
      if (self.searchDisplayController.active) { 
     [self.detailViewController setDetailItem:[self.searchResults objectAtIndex:indexPath.row]]; 
} 
    else 
     [self.detailViewController setDetailItem:[[contentsList objectAtIndex:indexPath.section] 
                objectAtIndex: indexPath.row]]; 

} 

#pragma mark - 
#pragma mark UISearchDisplayController Delegate Methods 

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller 
shouldReloadTableForSearchString:(NSString *)searchString 
{ 
    [self handleSearchForTerm:searchString]; 

    // Return YES to cause the search result table view to be reloaded. 

    return YES; 
} 

- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller 
{ 
    [self setSavedSearchTerm:nil]; 

    [[self mainTableView] reloadData];  
} 

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 

    if ([segue.identifier isEqualToString:@"detailview"]) { 
     if (self.searchDisplayController.active) { 
      self.detailViewController=segue.destinationViewController; 
     } 
     else 
     self.detailViewController=segue.destinationViewController; 
    } 
} 

@end 

내가 잘못거야 어디서 누군가가 말해 줄 수주십시오? 이것은 나를 미치게하고있다 INSANE !!!

답변

0

self.detailItem은 어떤 다른 사용자 정의 객체가 아닌 objectForKey에 응답하지 않는 상수 문자열이기 때문입니다.

클래스 정의가 게시되지 않았으므로 자세히 알려 드릴 수 없습니다.

+0

정의가 어떤 의미입니까? 미안해, 이거 처음이야? 그 밖의 무엇을 내 코드에서보아야 할 것이고 원래의 게시물을 편집 할 것입니다. – David

+0

'self.detailItem'에 어떤 종류의 객체가 저장되어 있다고 생각하는지 모르겠습니다. 기억할 수없는 'id'유형을 사용합니다. – trojanfoe

+0

원래 게시물을 편집하여 모든 코드를 보여주었습니다 (제품의 대부분을 빼면 거기에서 무슨 일이 일어나는지 아이디어를 얻으 려하지 않아도됩니다). 이것은 테이블보기에서 나가보기위한 방법입니다. 그것은 첫 번째 테이블보기에 대해서는 잘 작동하지만 결과에는 적합하지 않습니다. – David

관련 문제