自定义UITableViewCell无法出列

时间:2015-10-06 00:13:11

标签: ios swift uitableview

我有以下 <!DOCTYPE html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> </head> <body> <h1>iframe testing</h1> <script type="text/javascript"> $(document).ready(function() { alert("window.location.href"+window.location.href); }); </script> </body> </html>

的子类
UITableViewCell

然后我将原型单元格上的标识符设置为 AlbumTableViewCellIdentifier

enter image description here

最后,在我的视图控制器中,我已经分配了一个字符串值,我在控制器中使用它来表示标识符。

import UIKit

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

在同一个视图控制器中,我有以下class HomeViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { let AlbumTableViewCellIdentifier = "AlbumTableViewCellIdentifier"; } 方法。

cellforRowAtIndexPath

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; } 方法的第二行引发异常。

cellForRowAtIndexPath

这听起来像是找到我的自定义单元类的问题,但我不确定发生了什么。

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

我做错了是什么导致它没有为我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 正确出列?

修改

我还确保我的自定义类已分配给我的UITableViewCell

子类

enter image description here

0 个答案:

没有答案