我正在使用第三方库来显示带有箭头的滑动菜单的下拉单元格以打开子类别。使用APExpandableTableView
我收到错误消息:
"由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:' - [__ NSCFString objectAtIndex:]:无法识别的选择器发送到实例0x7f8612e834f0"。
我不知道自己做错了什么。
- (void)viewDidLoad {
[super viewDidLoad];
self.expandableTableView.expandableTableViewDelegate = self;
[self customSetup];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
-(void)customSetup
{
newArray = [[NSMutableArray alloc] init];
NSString *apiURL = [NSString stringWithFormat:@"%@/products/categories",mainURL];
OAuth1Legged *OAuth = [[OAuth1Legged alloc] init];
NSString *finalURL = [OAuth generateGetURL:apiURL];
[OAuth getJsonResponse:finalURL success:^(NSDictionary *responseDict)
{
dispatch_async( dispatch_get_main_queue(), ^{
self.dataModelArray = [[NSMutableArray alloc] init];
NSMutableDictionary *productCategories = [[NSMutableDictionary alloc] init];
productCategories = [responseDict objectForKey:@"product_categories"];
NSLog(@"Response %@ ", productCategories);
self.responseJSON = responseDict;
if ([self.responseJSON isKindOfClass:[NSDictionary class]]){ //Added instrospection as suggested in comment.
dictionaryArray= [self.responseJSON objectForKey:@"product_categories"];
if ([dictionaryArray isKindOfClass:[NSArray class]]){
//Added instrospection as suggested in comment.
for (NSDictionary *dictionary in dictionaryArray) {
CategoryBO *categoryBO = [[CategoryBO alloc] init];
categoryBO.categoryName = [dictionary objectForKey:@"name"];
categoryBO.categoryProductId = [dictionary objectForKey:@"id"];
categoryBO.categoryParentID = [dictionary objectForKey:@"parent"];
[newArray addObject:categoryBO];
}
}
}
NSLog(@"Data Array: %@",newArray);
for(int i = 0; i<[newArray count];i++)
{
NSLog(@"%@",[[newArray objectAtIndex:i] categoryName]);
[self.dataModelArray addObject:[[newArray objectAtIndex:i] categoryName]] ;
}
NSLog(@"Data %@", self.dataModelArray);
[self.expandableTableView reloadData];
});
} failure:^(NSError *error) {
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)expandableTableView:(APExpandableTableView *)tableView numberOfChildrenForGroupAtIndex:(NSInteger)groupIndex {
return [[self.dataModelArray objectAtIndex:groupIndex] count] - 1;
}
- (NSInteger)numberOfGroupsInExpandableTableView:(APExpandableTableView *)tableView {
return [self.dataModelArray count];
}
- (UITableViewCell *)expandableTableView:(APExpandableTableView *)tableView cellForChildAtIndex:(NSInteger)childIndex groupIndex:(NSInteger)groupIndex {
NSString *cellIdentifier = @"SampleChildCell";
UITableViewCell *cell = [self.expandableTableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = [[self.dataModelArray objectAtIndex:groupIndex] objectAtIndex:childIndex + 1];
return cell;
}
- (UITableViewCell *)expandableTableView:(APExpandableTableView *)tableView cellForGroupAtIndex:(NSInteger)groupIndex {
NSString *cellIdentifier = @"SampleGroupCell";
UITableViewCell *cell = [self.expandableTableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = [[self.dataModelArray objectAtIndex:groupIndex] objectAtIndex:0];
return cell;
}
- (void)expandableTableView:(APExpandableTableView *)tableView deleteChildAtIndex:(NSInteger)childIndex groupIndex:(NSInteger)groupIndex {
[[self.dataModelArray objectAtIndex:groupIndex] removeObjectAtIndex:childIndex + 1];
}
- (void)expandableTableView:(APExpandableTableView *)tableView moveChildAtIndex:(NSInteger)sourceIndex toIndex:(NSInteger)destinationIndex groupIndex:(NSInteger)groupIndex {
NSString *moveObject = [[self.dataModelArray objectAtIndex:groupIndex] objectAtIndex:sourceIndex + 1];
[[self.dataModelArray objectAtIndex:groupIndex] removeObjectAtIndex:sourceIndex + 1];
[[self.dataModelArray objectAtIndex:groupIndex] insertObject:moveObject atIndex:destinationIndex + 1];
}
- (void)expandableTableView:(APExpandableTableView *)tableView moveGroupAtIndex:(NSInteger)sourceIndex toIndex:(NSInteger)destinationIndex {
NSMutableArray *moveObject = [self.dataModelArray objectAtIndex:sourceIndex];
[self.dataModelArray removeObjectAtIndex:sourceIndex];
[self.dataModelArray insertObject:moveObject atIndex:destinationIndex];
}