0
votes

I'm receiving an error message when I run my app in Xcode (terminating app due to uncaught exception). Below I pasted the error message and what I believe is the part of the code that's creating the problem. I'm new and just learning objective c so please be easy with me. Thank you!

int main(int argc, char * argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); Thread 1:signal SIGABRT
    }
}
  • The Error Message:

    2014-11-25 10:07:19.794 SamplePhotoReDo[81276:108898068] * Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UITableView.m:6116 2014-11-25 10:07:19.798 SamplePhotoReDo[81276:108898068] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier AllPhotosCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard' *** First throw call stack:'

The script that I believe is causing the error:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;
    NSString *localizedTitle = nil;

    if (indexPath.section == 0) {
        cell = [tableView dequeueReusableCellWithIdentifier:AllPhotosReuseIdentifier forIndexPath:indexPath];
        localizedTitle = NSLocalizedString(@"All Photos", @"");
    } else {
        cell = [tableView dequeueReusableCellWithIdentifier:CollectionCellReuseIdentifier forIndexPath:indexPath];
        PHFetchResult *fetchResult = self.collectionsFetchResults[indexPath.section - 1];
        PHCollection *collection = fetchResult[indexPath.row];
        localizedTitle = collection.localizedTitle;
    }
    cell.textLabel.text = localizedTitle;

    return cell;
}
1
The key is this: 'must register a nib or a class for the identifier or connect a prototype cell in a storyboard'. This means you have to tell Xcode what cell belongs to which cell identifier. You can do this in code or in Interface Builder. - dasdom
Disregard, think I found the problem - Ray
Thank you dasdom for your quick response but I think I resolved the problem. In the storyboard changed the Table View content from dynamic to static.. That fixed the first error message but now I have another error message: *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 2 beyond bounds [0 .. 0]' - Ray
You try to excess an object at the index 2 in an array which is empty. Add a break point at 'All Exceptions' and reproduce the crash. - dasdom
Thank you again for your help dasdom.. As I mentioned earlier, Im new to objective c so sorry for this stupid question but is the script below part of the NSArray thats causing the problem? Im not sure how to add a break point.. - (NSArray *)assetsAtIndexPaths:(NSArray *)indexPaths { if (indexPaths.count == 0) { return nil; } NSMutableArray *assets = [NSMutableArray arrayWithCapacity:indexPaths.count]; for (NSIndexPath *indexPath in indexPaths) { PHAsset *asset = self.assetsFetchResults[indexPath.item]; [assets addObject:asset]; } return assets; } - Ray

1 Answers

0
votes

in ViewDidLoad add:

[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:AllPhotosReuseIdentifier];