问题描述
使用UItables设置设置菜单。由于某些原因“ [_listener didSelectItem:indexPath dataSource:self]”抛出异常“无法识别的选择器发送到实例”。很难理解为什么会这样。 任何指针将不胜感激!
xCode view of line that throws the exception
#import "CCSelectorViewController.h"
#import "CCDataSourceSection_Title.h"
#import "CCSelector_Cell.h"
#import "CCTableDataSource.h"
#define DID_SELECT_ITEM NSSelectorFromString(@"didSelectItem:dataSource:")
#define DID_deselect_ITEM NSSelectorFromString(@"diddeselectItem:dataSource:")
@interface CCSelectorViewController()
@end
@implementation CCSelectorItem
-(instancetype)initSelected:(BOOL)selected{
self = [super init];
if( self != NULL){
_selected = selected;
}
return self;
}
-(Nsstring *)title{
[CCAssert ASSERT:NO message:@"Needs Implementation"];
return NULL;
}
@end
@interface CCSelectorViewControllerDataSource()
@property (weak) id<CCSelectorViewControllerListener> listener;
@end
@implementation CCSelectorViewControllerDataSource
-(instancetype)initWithTable:(UITableView *)table items:(NSArray*)items multiSelect:(BOOL)multiSelect listener:(id<CCSelectorViewControllerListener>)listener{
self = [super initWithTable:table];
if( self != NULL ){
table.allowsMultipleSelection = multiSelect;
table.tintColor = [CCView OptionSelectColor];
_listener = listener;
[self populateWithItems:items];
}
return self;
}
-(void)populateWithItems:(NSArray*)items{
CCDataSourceSections result = [CCDataSource createSections];
CCDataSourceSection_Title* section = [[CCDataSourceSection_Title alloc] initWithTitle:NULL];
[section addEntries:items];
[result addobject:section];
[self reloadSections:result];
}
-(void)setAllSelected:(BOOL)selected{
for( CCSelectorItem* item in [self entriesForSection:0]){
NSIndexPath* indexPath = [self indexPathOfObject:item];
if( selected ){
[self tableView: [self getTable] didSelectRowAtIndexPath:indexPath];
}else{
[self tableView: [self getTable] diddeselectRowAtIndexPath:indexPath];
}
}
[self reloadData];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
CCSelector_Cell* result;
CCSelectorItem* item = (CCSelectorItem*)[self objectAtIndexPath:indexPath];
{
result = [CCTableView_Cell dequeueReusableCellForTable:tableView aClass:[CCSelector_Cell class]];
{
[result setup:item tableView:tableView indexPath:indexPath];
}
}
return result;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
CCSelectorItem* item = (CCSelectorItem*)[self objectAtIndexPath:indexPath];
item.selected = YES;
CCSelector_Cell* cell = [tableView cellForRowAtIndexPath:indexPath];
{
[cell refresh:tableView indexPath:indexPath];
}
[_listener didSelectItem:indexPath dataSource:self];
}
-(void)tableView:(UITableView *)tableView diddeselectRowAtIndexPath:(NSIndexPath *)indexPath{
CCSelectorItem* item = (CCSelectorItem*)[self objectAtIndexPath:indexPath];
item.selected = NO;
CCSelector_Cell* cell = [tableView cellForRowAtIndexPath:indexPath];
{
[cell refresh:tableView indexPath:indexPath];
}
[_listener diddeselectItem:indexPath dataSource:self];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return [CCView UIMULTIPLIER] * 44;
}
@end
@interface CCSelectorViewController ()
@property (weak,nonatomic) IBOutlet UITableView *tableView;
@property CCSelectorViewControllerDataSource* dataSource;
@property Nsstring* aTitle;
@property NSArray* items;
@property BOOL multiSelect;
@property NSDictionary* exTradata;
@property (weak) id<CCSelectorViewControllerListener> listener;
@end
@implementation CCSelectorViewController
-(void)setupWithTitle:(Nsstring*)title items:(NSArray*)items multiSelect:(BOOL)multiSelect exTradata:(NSDictionary*)exTradata listener:(id<CCSelectorViewControllerListener>)listener{
_aTitle = title;
_items = items;
_multiSelect = multiSelect;
_exTradata = exTradata;
_listener = listener;
}
-(void)viewDidLoad{
[super viewDidLoad];
self.title = _aTitle;
_dataSource = [[CCSelectorViewControllerDataSource alloc] initWithTable:_tableView items:_items multiSelect:_multiSelect listener:_listener];
}
-(void)addNavigationItems{
//override so that we dont add the x in the top right
}
-(void)goBack:(id)sender{
[super goBack:sender];
CCDataSourceSection* section = [_dataSource sectionAtIndex:0];
[_listener onComplete:[section entries] exTradata:_exTradata];
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
@end
这是:EdgeAnalyticsPageView_Cell.m
#import "EdgeAnalyticPageView_Cell.h"
#import "EdgeAnalyticViewController.h"
@interface EdgeAnalyticPageView_Cell()
@property (nonatomic,strong) EdgeAnalyticViewController* parent;
@property (nonatomic) EdgeAnalyticField* field;
@property (nonatomic) EdgeAnalyticField* parentField;
@property (nonatomic) NSUInteger pageIndex;
@end
@implementation EdgeAnalyticPageView_Cell
-(void)setup:(EdgeAnalyticField*)field parentField:(EdgeAnalyticField*)parentField pageIndex:(NSUInteger)pageIndex parent:(__weak EdgeAnalyticViewController*)parent{
_parent = parent;
_field = field;
_parentField = parentField;
_pageIndex = pageIndex;
[self onSetup:_field parentField:_parentField pageIndex:_pageIndex parent:_parent];
}
-(void)onSetup:(EdgeAnalyticField*)field parentField:(EdgeAnalyticField*)parentField pageIndex:(NSUInteger)pageIndex parent:(__weak EdgeAnalyticViewController*)parent{
[CCAssert ASSERT:NO message:@"Needs Implementation"];
}
-(BOOL)isEnabled{
return [_parent fieldEnabled:_field];
}
-(NSUInteger)pageIndex{
return _pageIndex;
}
-(EdgeAnalyticField*)field{
return _field;
}
-(EdgeAnalyticField*)parentField{
return _parentField;
}
-(EdgeAnalyticViewController*)parent{
return _parent;
}
@end
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)