我收到的错误似乎无法解决:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[UICollectionViewController setSearchString:]: unrecognized
selector sent to instance 0x7fcd4b655930'
当我调用prepareForSegue方法时出现错误:
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSString *searchStringToPass = [[NSString alloc]initWithFormat:_inputField.text];
UINavigationController *navController = [segue destinationViewController];
ResultsCollectionViewController *rvc = (ResultsCollectionViewController *)([navController viewControllers][0]);
NSLog(@"Search String to Pass is: %@", searchStringToPass);
//[rvc setSearchString:searchStringToPass];
rvc.searchString = searchStringToPass;
//userViewController.user = [self.users objectInListAtIndex:[self.tableView indexPathForSelectedRow].row];
}
我想要的ViewController嵌入在导航控制器中。它的代码是:
#import "ResultsCollectionViewController.h"
@interface ResultsCollectionViewController ()
//@property(nonatomic, weak) IBOutlet UICollectionView *collectionView;
@property(strong, nonatomic) NSArray *flickrPhotos;
@end
@implementation ResultsCollectionViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(@"search string is %@",_searchString);
}
-(void)getFlickrPhotosWithSearchString:(NSString*)searchString{
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
.h文件是:
#import "BaseViewController.h"
@interface ResultsCollectionViewController : BaseViewController <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (strong, nonatomic) NSString *searchString;
@end
任何人都知道问题是什么?提前谢谢了。
答案 0 :(得分:2)
您报告以下错误消息:
- [UICollectionViewController setSearchString:]:无法识别的选择器发送到实例0x7fcd4b655930
请注意&#34;无法识别的选择器&#34;在错误消息中是您的searchString
属性的setter访问器方法,但引用的类是标准UICollectionVieController
,而不是您的自定义类。
这表明您忽略了在Interface Builder中为目标场景指定基类。故事板因此实例化了标准UICollectionViewController
而不是您的自定义类,因此找不到您的searchString
访问者方法。