NSArrayM tableView]:无法识别的选择器

时间:2014-05-16 12:29:58

标签: ios objective-c uitableview unrecognized-selector

我有两天被困,因为我的NSArray不起作用。

当我运行应用程序时一切正常但是当我触摸searchBar时,应用程序关闭原因:' - [__NSArrayM tableView]:无法识别的选择器发送到实例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

1 个答案:

答案 0 :(得分:3)

在Objective-C中,&#34;无法识别的选择器&#34;错误意味着您尝试在对象上执行方法(即&#34;向其发送消息&#34;其中&#34;消息&#34;由&#34;选择器&#34;标识),但该对象没有实现该方法(即&#34;不识别选择器&#34;)。

当你有一个错误类的对象时,通常会发生这种情况。在这种情况下,我猜测setParentController:的{​​{1}}方法需要一些实现searchBar的对象(可能tableView,因为我看到它有self }}属性,这意味着它有一个tableView getter方法),但你给它tableView代替。这只是一个猜测,因为你的其余代码都缺失了。 (例如&#39; s monthArray?)

相关问题