以下是我正在添加搜索栏并执行操作的视图控制器的代码:
SearchViewController.h
#import <UIKit/UIKit.h>
@interface SearchViewController : UIViewController <UITextFieldDelegate>
@property (strong, nonatomic) IBOutlet UISearchBar *search;
@end
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
点击搜索栏输入文字时,我收到错误:
- [SearchViewController tableView:numberOfRowsInSection:]:无法识别的选择器发送到实例0x8e68990
答案 0 :(得分:1)
从错误看,您的应用程序也尝试查找表视图委托方法。几个支票