我有两天被困,因为我的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
在Objective-C中,“无法识别的选择器”错误表示您试图在对象上执行方法(即“向其发送消息”,其中“消息”由“选择器”标识),但是该对象没有实现该方法(即“无法识别该选择器”)。
当您拥有错误类的对象时,通常会发生这种情况。在这种情况下,我猜想setParentController:
您的方法searchBar
期望某个实现的对象tableView
(也许self
是因为我看到它具有一个tableView
属性,这意味着它具有一个tableView
getter方法),但您却给了它monthArray
。不过,这只是一个猜测,因为其余的代码丢失了。(例如什么JPSearchBar
?)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句