0

I have the following subclass of UITableViewCell

import UIKit

public class AlbumTableViewCell : UITableViewCell {
    @IBOutlet weak var albumNameLabel: UILabel!
    @IBOutlet weak var albumThumbnailImage: UIImageView!
}

I then have the identifier on a prototype cell set to AlbumTableViewCellIdentifier.

enter image description here

Finally, in my view controller, I have assigned a string value that I use in the controller to represent the identifier.

class HomeViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    let AlbumTableViewCellIdentifier = "AlbumTableViewCellIdentifier";
}

Within the same view controller, I have the following cellforRowAtIndexPath method.

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell:AlbumTableViewCell;
    cell = tableView.dequeueReusableCellWithIdentifier(AlbumTableViewCellIdentifier, forIndexPath: indexPath) as! AlbumTableViewCell;

    let currentTag = cell.tag + 1;
    cell.tag = currentTag;

    let album:PHAssetCollection = self.albums[indexPath.row] as! PHAssetCollection;
    cell.albumNameLabel.text = album.localizedTitle;

    // No assets were returned for this collection, so we can't assign an album thumbnail.
    let assetFetchResult:PHFetchResult = PHAsset.fetchAssetsInAssetCollection(album, options: nil);
    if (assetFetchResult.count == 0) {
        return cell;
    }

    let asset = assetFetchResult.objectAtIndex(0);
    self.imageManager.requestImageForAsset(
        asset as! PHAsset,
        targetSize: AssetGridThumbnailSize,
        contentMode: PHImageContentMode.AspectFill,
        options: nil) { (image, info) -> Void in
            if (cell.tag == currentTag) {
                cell.albumThumbnailImage.image = image;
            }
    }

    return cell;
}

The second line of the cellForRowAtIndexPath method throws an exception.

    cell = tableView.dequeueReusableCellWithIdentifier(AlbumTableViewCellIdentifier, forIndexPath: indexPath) as! AlbumTableViewCell;

It sounds like an issue finding my custom cell class, but i'm not sure what's going on.

2015-10-05 17:05:25.562 Bokeh[24962:3695240] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Bokeh.AlbumTableViewCell 0x7fe371c5c250> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key cell.'
    *** First throw call stack:
    (
        0   CoreFoundation                      0x0000000106b9ef65 __exceptionPreprocess + 165
        1   libobjc.A.dylib                     0x0000000108b91deb objc_exception_throw + 48
        2   CoreFoundation                      0x0000000106b9eba9 -[NSException raise] + 9
        3   Foundation                          0x0000000106f66f5b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
        4   UIKit                               0x00000001077cac4b -[UIView(CALayerDelegate) setValue:forKey:] + 173
        5   UIKit                               0x0000000107aba923 -[UIRuntimeOutletConnection connect] + 109
        6   CoreFoundation                      0x0000000106adfb10 -[NSArray makeObjectsPerformSelector:] + 224
        7   UIKit                               0x0000000107ab9306 -[UINib instantiateWithOwner:options:] + 1864
        8   UIKit                               0x00000001078572a5 -[UITableView _dequeueReusableViewOfType:withIdentifier:] + 388
        9   Bokeh                               0x00000001069ac06e _TFC5Bokeh18HomeViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 126
        10  Bokeh                               0x00000001069ac92f _TToFC5Bokeh18HomeViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 79
        11  UIKit                               0x00000001078696b3 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 782
        12  UIKit                               0x00000001078697c8 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
        13  UIKit                               0x000000010783f650 -[UITableView _updateVisibleCellsNow:isRecursive:] + 3187
        14  UIKit                               0x0000000107872595 -[UITableView _performWithCachedTraitCollection:] + 92
        15  UIKit                               0x000000010785a9ad -[UITableView layoutSubviews] + 218
        16  UIKit                               0x00000001077cb11c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
        17  QuartzCore                          0x00000001075d536a -[CALayer layoutSublayers] + 146
        18  QuartzCore                          0x00000001075c9bd0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
        19  QuartzCore                          0x00000001075c9a4e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
        20  QuartzCore                          0x00000001075be1d5 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
        21  QuartzCore                          0x00000001075eb9f0 _ZN2CA11Transaction6commitEv + 508
        22  QuartzCore                          0x00000001075ec154 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
        23  CoreFoundation                      0x0000000106aca9d7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
        24  CoreFoundation                      0x0000000106aca947 __CFRunLoopDoObservers + 391
        25  CoreFoundation                      0x0000000106abfebc CFRunLoopRunSpecific + 524
        26  UIKit                               0x000000010771598d -[UIApplication _run] + 402
        27  UIKit                               0x000000010771a676 UIApplicationMain + 171
        28  Bokeh                               0x00000001069a907d main + 109
        29  libdyld.dylib                       0x00000001096e292d start + 1
        30  ???                                 0x0000000000000001 0x0 + 1
    )
    libc++abi.dylib: terminating with uncaught exception of type NSException

What am I doing wrong that is causing it to not properly dequeue a UITableViewCell for me?

Edit

I have also made sure that my Custom Class has been assigned to my subclass of UITableViewCell

enter image description here

Johnathon Sullinger
  • 7,097
  • 5
  • 37
  • 102

0 Answers0