获取 - [SearchViewController tableView:numberOfRowsInSection:]:无法识别的选择器发送到实例

时间:2014-09-13 06:17:03

标签: ios uisearchbar

以下是我正在添加搜索栏并执行操作的视图控制器的代码:

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

1 个答案:

答案 0 :(得分:1)

从错误看,您的应用程序也尝试查找表视图委托方法。几个支票

  1. 您可以删除代码吗? “MMDrawerController / UIViewController + MMDrawerController.h”并尝试?
  2. 您的nib文件是否包含表格视图?如果是,你可以检查它是否 是否连接到任何IBOutlets?