[英]Getting -[SearchViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance
The following is the code for a View Controller in which I'm adding a Search bar and performing things: 以下是View Controller的代码,其中添加了搜索栏并执行操作:
SearchViewController.h SearchViewController.h
#import <UIKit/UIKit.h>
@interface SearchViewController : UIViewController <UITextFieldDelegate>
@property (strong, nonatomic) IBOutlet UISearchBar *search;
@end
SearchViewController.m SearchViewController.m
#import "SearchViewController.h"
#import "MMDrawerController/UIViewController+MMDrawerController.h"
@interface SearchViewController ()
@end
@implementation SearchViewController
@synthesize search;
- (BOOL)prefersStatusBarHidden
{
return YES;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[search.delegate self];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
[self.view addGestureRecognizer:tap];
[search setShowsCancelButton:YES animated:NO];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - UITextFieldMethod
-(void) textFieldDidEndEditing:(UITextField *)textField
{
[search resignFirstResponder];
}
-(BOOL) textFieldShouldReturn:(UITextField *)textField
{
[search resignFirstResponder];
return YES;
}
#pragma mark - HandlingKeyboard
-(void) dismissKeyboard
{
[search resignFirstResponder];
}
#pragma mark - UISearchBarMethods
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[search resignFirstResponder];
[search endEditing:YES];
[self.mm_drawerController toggleDrawerSide:MMDrawerSideRight animated:YES completion:nil];
}
- (void) searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
[search resignFirstResponder];
[self.mm_drawerController toggleDrawerSide:MMDrawerSideRight animated:YES completion:nil];
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
[search resignFirstResponder];
}
@end
While clicking in the search bar to enter text, I'm getting an error of: 在搜索栏中单击以输入文本时,出现以下错误:
-[SearchViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x8e68990 -[SearchViewController tableView:numberOfRowsInSection:]:无法识别的选择器已发送到实例0x8e68990
From error it looks like that your app try too find table view delegate methods. 从错误看来您的应用程序也尝试查找表视图委托方法。 Couple of check 几张支票
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.