简体   繁体   中英

NSArrayM tableView]: unrecognized selector

I have two days trapped because do not work my NSArray.

when I run the application everything works well but when I touch searchBar the application is closed reason: '- [__NSArrayM tableView]: unrecognized selector sent to instance 0x16e34c50'

@implementation ViewController


-(BOOL)prefersStatusBarHidden
{
return YES;
}
- (void)viewDidLoad

{
[super viewDidLoad];

monthArray = [[ NSMutableArray alloc] initWithObjects:@"Paliwizumab",@"Opis przedmiotu zamówienia",@"Paliwizumab a 0,1g inj I.M ( proszek + rozpuszczalnik)",@"Paliwizumab a 0,05 g I.M ( proszek + rozpuszczalnik )",@"Nazwa międzynarodowa",@"PALIVISUMABUM*",@"Paliwizumab01",@"Paliwizumab02",@"Paliwizumab03",@"Paliwizumab04",@"Paliwizumab05",@"Paliwizumab06", nil];


[searchBar setParentController:self];
[searchBar setParentController:monthArray];
[searchBar setDelegate:searchBar];


[self prefersStatusBarHidden];

}
-(void) viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:searchBar selector:@selector(keyboardWillShow:) name:          (UIKeyboardWillShowNotification ) object:nil];
}

-(void)viewDidDisappear:(BOOL)animated

[super viewDidDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:searchBar];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[self monthArray]count];

}   


-(NSMutableArray*)monthArray
{
if (searchBar.isSearching == 1)
    return  searchBar.searchArray;

else
    return  monthArray;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *CellId = @"CellId";
UITableViewCell *cell = [self->_tableView dequeueReusableCellWithIdentifier:CellId];
if (! cell)
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellId];
[cell.textLabel setText:[[self monthArray] objectAtIndex:indexPath. row]];
return cell;

}



@end

ViewController.h

#import <UIKit/UIKit.h>
#import "JPSearchBar.h"

@interface ViewController : UIViewController<UITableViewDelegate>

 {
NSMutableArray       *monthArray;
IBOutlet JPSearchBar *searchBar;
}


@property (strong, nonatomic) IBOutlet UITableView *tableView;

-(NSMutableArray*)monthArray;


@end

In Objective-C, the "unrecognized selector" error means that you tried to execute a method on an object (ie "send it a message" where the "message" is identified by a "selector"), but the object doesn't implement that method (ie "doesn't recognize that selector").

This often happens when you have an object of the wrong class. In this case I'm guessing that the setParentController: method of your searchBar expects some object that implements tableView (maybe self because I see it has a tableView property which means it has a tableView getter method) but you give it monthArray instead. This is just a guess though, because the rest of your code is missing. (Eg what's JPSearchBar ?)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM