由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [__ NSCFDictionary objectAtIndex:]:

时间:2015-11-11 08:36:06

标签: objective-c iphone arrays dictionary plist

您好我的代码中有点怀疑。 我正在恢复数据对象类以插入集合视图,首先成功管理。 但在第二次失败中。

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {


CustomerCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyCell" forIndexPath:indexPath];

ButtonSettings * button = [[CVDataController sharedInstance].LBData objectAtIndex:indexPath.row];

[cell.nameServicosButton setTitle:button.Title forState:UIControlStateNormal];

if ([[CVDataController sharedInstance].listData count] > 0) {
    [cell.nameServicosButton addTarget:self action:@selector(novajanela) forControlEvents:UIControlEventTouchUpInside];
    NSLog(@"Maior");
}else{
    NSLog(@"Menor");
}

cell.customerImage.image = [UIImage imageNamed:button.Image];

return cell;
}

这是第一个以这种方式工作并正常运行的ViewController。

Esta é a minha estrutura do Plist

我需要检索此数组中名为Button Settings的信息,该信息位于Dicionario中。

我的班级谁控制数据。

- (instancetype)initWithDataPList {

self = [super init];

if (self) {
    NSMutableArray * lb = [PlistManager loadMutableArrayFromPlist:@"ListadeEspera" location:@"doc"];
    if (lb.count>0) {

        NSMutableArray * leaderBoardList = [NSMutableArray new];

        for (NSMutableDictionary * dicPlayer in lb) {

            ButtonSettings * player = [[ButtonSettings alloc] initWithDictionary:dicPlayer];

            [leaderBoardList addObject:player];
        }
        _LBData = [leaderBoardList mutableCopy];
    }
    if (_LBData.count>0) {

        NSMutableArray * leaderBoardList = [NSMutableArray new];

        for (ButtonSettings * buttom in _LBData) {

            NSMutableDictionary * dicPlayer = [NSMutableDictionary new];
            [dicPlayer setValue:buttom.buttonData forKey:@"ButtoSettings"];

            [leaderBoardList addObject:dicPlayer];
        }
        _listData = [leaderBoardList mutableCopy];

    }
}
return self;
}

你需要一种方法来加载listData只包含来自ButtonSettings的信息,如果我放一个NSLog这个listData将只显示由于过滤器放置而导致的与ButtonSettings相关的信息,但及时启动此代码摘录显示错误。< / p>

这是第二个控制器的代码视图

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {


CustomerCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyCell" forIndexPath:indexPath];


ButtonSettings * button = [[ButtonSettings alloc] init];
button.buttonData = [[CVDataController sharedInstance].listData objectAtIndex:indexPath.row];

NSMutableDictionary * dicData = [[NSMutableDictionary alloc] init];

NSString * titleData = [dicData objectForKey:@"Title"];
NSLog(@"%@",titleData);

[cell.nameServicosButton setTitle:button.Title forState:UIControlStateNormal];


if ([[CVDataController sharedInstance].listData count] > 0) {
    [cell.nameServicosButton addTarget:self action:@selector(novajanela) forControlEvents:UIControlEventTouchUpInside];
}else{
    NSLog(@"Menor");
}

cell.customerImage.image = [UIImage imageNamed:button.Image];

return cell;
}

我尝试过与第一个ViewController相同但错误的方法。

0 个答案:

没有答案