CustomCell是SIGABRT错误[W / code]空或结果 [英] CustomCell is empty or results in SIGABRT error [W/Code]

查看:1024
本文介绍了CustomCell是SIGABRT错误[W / code]空或结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个显示在一个UITableView缩略图,标题和视频的说明一个视频播放器。当用户点击原始它会打开与其中视频将发挥的WebView一个新的视角。

在present目前我仍然在试图设置自定义单元格。我得到上的 AppDelegate.swift 文件错误类的AppDelegate:UIResponder,UIApplicationDelegate {线和错误是:主题1:信号SIGABRT 。错误日志是在这篇文章的末尾。

Main.storyboard 我添加了一个TableView中(我连接到ViewController与代表数据源)一个原型细胞,在那里我增加了一个ImageView的和两个标签。我还创建了一个名为斯威夫特文件 CustomTableViewCell.swift 。我设置了视图控制器自定义类来的ViewController,小区的标识符 customCell ,风格为自定义,它是类 CustomTableViewCell

ViewController.swift 我创建的视频信息的数组,我设置了表函数。

我也试过其他的方式来写code。与解决方案,我发现这里的堆栈,但我也得到了同样的错误,或在最大,我收到了表3空单元格。在code是下面的人。有人可以告诉如何将这个定制单元的工作好吗?

在此先感谢!

Main.storyboard href=\"http://i.stack.imgur.com/3zj8t.png\" rel=\"nofollow\">

  ViewController.swift//
// ViewController.swift
//摆线
//
//创建者桑德罗西门斯在15年10月11日。
//版权所有©2015年桑德罗·西门斯。版权所有。
//进口的UIKitVAR视频= [字典<字符串,字符串>()]一流的ViewController:UIViewController的,的UITableViewDelegate,UITableViewDataSource {    @IBOutlet VAR的tableView:UITableView的!    覆盖FUNC viewDidLoad中(){
        super.viewDidLoad()        如果videos.count == 1 {            videos.removeAtIndex(0)            //检查的地方!= 1也不是0,因为我们创造了字典的地方作为外的ViewController一个全局变量,并且不能为空。        }        videos.append([称号:视频1,说明:说明1\",\"thumbnail\":\"http://img.youtube.com/vi/6oXTFb-52Zc/0.jpg\",\"video\":\"https://www.youtube.com/watch?v=6oXTFb-52Zc\"])
        videos.append([称号:视频2,说明:说明2\",\"thumbnail\":\"http://img.youtube.com/vi/dkwuCeCQVg8/0.jpg\",\"video\":\"https://www.youtube.com/watch?v=dkwuCeCQVg8\"])
        videos.append([称号:视频3,说明:说明3\",\"thumbnail\":\"http://img.youtube.com/vi/6Zf_70xM1Cw/0.jpg\",\"video\":\"https://www.youtube.com/watch?v=6Zf_70xM1Cw\"])    }FUNC numberOfSectionsInTableView(的tableView:UITableView的) - GT; INT {        返回1
    }FUNC的tableView(的tableView:UITableView的,numberOfRowsInSection段中:int) - GT; INT {        回报videos.count    }    / *
    //如果我用这个没有SIGABRT错误,但细胞是空的。
        FUNC的tableView(的tableView:UITableView的,的cellForRowAtIndexPath indexPath:NSIndexPath) - GT; {的UITableViewCell            让细胞:=的UITableViewCell UITableViewCell中(样式:UITableViewCellStyle.Default,reuseIdentifier:customCell)            回报细胞    * /FUNC的tableView(的tableView:UITableView的,的cellForRowAtIndexPath indexPath:NSIndexPath) - GT; {的UITableViewCell        让细胞= tableView.dequeueReusableCellWithIdentifier(customCell,forIndexPath:indexPath)作为! CustomTableViewCell        让URL = NSURL(字符串:视频[indexPath.row] [缩略图]!)
            让数据= NSData的(contentsOfURL:网址!)        ?cell.img =图像配的UIImage(数据:数据!)
        cell.ttl?的.text =视频[indexPath.row] [称号]
        cell.dsc?的.text =视频[indexPath.row] [说明]        回报细胞}    覆盖FUNC didReceiveMemoryWarning(){
        super.didReceiveMemoryWarning()
        可以重新创建任何资源的处置//。
    }}

CustomTableView.swift

  //
    // CustomTableViewCell.swift
    //摆线
    //
    //进口基金会
    进口的UIKit    类CustomTableViewCell:{的UITableViewCell        @IBOutlet弱VAR IMG:UIImageView的!        @IBOutlet弱VAR TTL:的UILabel!        @IBOutlet弱VAR DSC:的UILabel!//我也试着删除下面的code。        覆盖FUNC awakeFromNib(){
            super.awakeFromNib()
        }        覆盖FUNC的setSelected(选择:BOOL,动画:BOOL){
            super.setSelected(选择动画:动画)
        }
    }

错误日志:

  2015年11月10日18:00:23.069摆线[5922:398570]未知类CustomTableViewCell在Interface Builder文件。
二○一五年十一月十日18:00:23.074摆线[5922:398570 ***终止应用程序由于未捕获的异常'NSUnknownKeyException',原因:'[< UITableViewCell的0x7f96da6a0030> setValue方法:forUndefinedKey:]:此类不是密钥值编码兼容的关键DSC。
***第一掷调用堆栈:

        0的CoreFoundation 0x000000010d55ef45 __exception preprocess + 165
        1 libobjc.A.dylib 0x000000010f282deb objc_exception_throw + 48
        2的CoreFoundation 0x000000010d55eb89 - [NSException提高] + 9
        3基金会0x000000010d927a6b - [NSObject的(即NSKeyValueCoding)的setValue:forKey:] + 288
        4 UIKit的0x000000010de2f96f - [UIView的(CALayerDelegate)的setValue:forKey:] + 173
        5 UIKit的0x000000010e133a71 - [UIRuntimeOutletConnection连接] + 109
        6的CoreFoundation 0x000000010d49fa80 - [NSArray的makeObjectsPerformSelector:] + 224
        7 UIKit的0x000000010e132454 - [UINib instantiateWithOwner:选项:] + 1864年
        8 UIKit的0x000000010debe177 - [UITableView的_dequeueReusableViewOfType:withIdentifier:] + 388
        9 UIKit的0x000000010debe549 - [UITableView的dequeueReusableCellWithIdentifier:forIndexPath:] + 71
        10摆线0x000000010d37a2dd _TFC7Cycloid14ViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 125
        11摆线0x000000010d37ac7f _TToFC7Cycloid14ViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 79
        12 UIKit的0x000000010ded0e2a - [UITableView的_create preparedCellForGlobalRow:withIndexPath:willDisplay:] + 782
        13 UIKit的0x000000010ded0f3f - [UITableView的_create preparedCellForGlobalRow:willDisplay:] + 74
        14 UIKit的0x000000010dea6307 - [UITableView的_updateVisibleCellsNow:isRecursive:] + 3187
        15 UIKit的0x000000010ded9d1c - [UITableView的_performWithCachedTraitCollection:] + 92
        16 UIKit的0x000000010dec1884 - [UITableView的layoutSubviews] + 223
        17 UIKit的0x000000010de2fe40 - [UIView的(CALayerDelegate)layoutSublayersOfLayer:] + 710
        18 QuartzCore 0x00000001122c559a - [CALayer的layoutSublayers] + 146
        19 QuartzCore 0x00000001122b9e70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
        20 QuartzCore 0x00000001122b9cee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
        21 QuartzCore 0x00000001122ae475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
        22 QuartzCore 0x00000001122dbc0a _ZN2CA11Transaction6commitEv + 486
        23 QuartzCore 0x00000001122dc37c _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
        24的CoreFoundation 0x000000010d48a947 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
        25的CoreFoundation 0x000000010d48a8b7 __CFRunLoopDoObservers + 391
        26的CoreFoundation 0x000000010d47fe2c CFRunLoopRunSpecific + 524
        27 UIKit的0x000000010dd764f5 - [UIApplication的_run] + 402
        28 UIKit的0x000000010dd7b30d UIApplicationMain + 171
        29摆线0x000000010d37be0d主+ 109
        30 libdyld.dylib 0x000000010fd8a92d启动+ 1

的libc ++ abi.dylib:类型NSException的未捕获的异常终止
(LLDB)


解决方案

去你的故事板,选择原型电池,免除您的自定义类(所以这是一个普通的的UITableViewCell 再次),生成项目一次,然后设置自定义类回 CustomTableViewCell 键,然后重试。

I'm trying to create a video player that displays in a UITableView the thumbnails, titles and descriptions of the videos. When the user clicks on the raw it will open a new view with a WebView where the video will be played.

In the present moment I'm still trying to set the custom cell. I'm getting an error on the AppDelegate.swift file on the class AppDelegate: UIResponder, UIApplicationDelegate { line and the error is: Thread 1: signal SIGABRT. The error log is at the end of this post.

In the Main.storyboard I added a TableView (that I connected to the ViewController with the delegate and dataSource) with one prototype cell, where I added an ImageView and two labels. I also created a Swift File named CustomTableViewCell.swift. I set the View Controller Custom Class to ViewController, the identifier of the cell to customCell, style to "Custom" and it's class to CustomTableViewCell.

In the ViewController.swift I created an array with the information of the videos and I set the table functions.

I also tried other ways to write the code with solutions that I found here on Stack but I also get the same error or in the max I get a table with 3 empty cells. The code is down below. Can someone please tell how to put this custom cells working please?

Thanks in advance!

ViewController.swift

//
//  ViewController.swift
//  Cycloid
//
//  Created by Sandro Simes on 10/11/15.
//  Copyright © 2015 Sandro Simes. All rights reserved.
//

import UIKit

var videos = [Dictionary<String,String>()]

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()

        if videos.count == 1 {

            videos.removeAtIndex(0)

            // Check if places != to 1 and not 0 because we created the dictionary places as a global var outside the ViewController and that can not be empty.

        }

        videos.append(["title":"Video 1","description":"Description 1","thumbnail":"http://img.youtube.com/vi/6oXTFb-52Zc/0.jpg","video":"https://www.youtube.com/watch?v=6oXTFb-52Zc"])
        videos.append(["title":"Video 2","description":"Description 2","thumbnail":"http://img.youtube.com/vi/dkwuCeCQVg8/0.jpg","video":"https://www.youtube.com/watch?v=dkwuCeCQVg8"])
        videos.append(["title":"Video 3","description":"Description 3","thumbnail":"http://img.youtube.com/vi/6Zf_70xM1Cw/0.jpg","video":"https://www.youtube.com/watch?v=6Zf_70xM1Cw"])

    }

func numberOfSectionsInTableView(tableView: UITableView) -> Int {

        return 1
    }

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return videos.count

    }

    /*
    //If I use this there is no SIGABRT error but the cells are empty.
        func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

            let cell:UITableViewCell = UITableViewCell(style:UITableViewCellStyle.Default, reuseIdentifier:  "customCell")

            return cell

    */

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCellWithIdentifier("customCell", forIndexPath: indexPath) as! CustomTableViewCell

        let url = NSURL(string: videos[indexPath.row]["thumbnail"]!)
            let data = NSData(contentsOfURL: url!)

        cell.img?.image = UIImage(data: data!)
        cell.ttl?.text = videos[indexPath.row]["title"]
        cell.dsc?.text = videos[indexPath.row]["description"]

        return cell

}

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

CustomTableView.swift

    //
    //  CustomTableViewCell.swift
    //  Cycloid
    //


    // import Foundation
    import UIKit

    class CustomTableViewCell: UITableViewCell {

        @IBOutlet weak var img: UIImageView!

        @IBOutlet weak var ttl: UILabel!

        @IBOutlet weak var dsc: UILabel!

// I also tried deleting the code below.

        override func awakeFromNib() {
            super.awakeFromNib()
        }

        override func setSelected(selected: Bool, animated: Bool) {
            super.setSelected(selected, animated: animated)
        }
    }

Error log:

2015-11-10 18:00:23.069 Cycloid[5922:398570] Unknown class CustomTableViewCell in Interface Builder file.
2015-11-10 18:00:23.074 Cycloid[5922:398570] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UITableViewCell 0x7f96da6a0030> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key dsc.'
*** First throw call stack:
(
        0   CoreFoundation                      0x000000010d55ef45 __exceptionPreprocess + 165
        1   libobjc.A.dylib                     0x000000010f282deb objc_exception_throw + 48
        2   CoreFoundation                      0x000000010d55eb89 -[NSException raise] + 9
        3   Foundation                          0x000000010d927a6b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
        4   UIKit                               0x000000010de2f96f -[UIView(CALayerDelegate) setValue:forKey:] + 173
        5   UIKit                               0x000000010e133a71 -[UIRuntimeOutletConnection connect] + 109
        6   CoreFoundation                      0x000000010d49fa80 -[NSArray makeObjectsPerformSelector:] + 224
        7   UIKit                               0x000000010e132454 -[UINib instantiateWithOwner:options:] + 1864
        8   UIKit                               0x000000010debe177 -[UITableView _dequeueReusableViewOfType:withIdentifier:] + 388
        9   UIKit                               0x000000010debe549 -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 71
        10  Cycloid                             0x000000010d37a2dd _TFC7Cycloid14ViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 125
        11  Cycloid                             0x000000010d37ac7f _TToFC7Cycloid14ViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 79
        12  UIKit                               0x000000010ded0e2a -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 782
        13  UIKit                               0x000000010ded0f3f -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
        14  UIKit                               0x000000010dea6307 -[UITableView _updateVisibleCellsNow:isRecursive:] + 3187
        15  UIKit                               0x000000010ded9d1c -[UITableView _performWithCachedTraitCollection:] + 92
        16  UIKit                               0x000000010dec1884 -[UITableView layoutSubviews] + 223
        17  UIKit                               0x000000010de2fe40 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
        18  QuartzCore                          0x00000001122c559a -[CALayer layoutSublayers] + 146
        19  QuartzCore                          0x00000001122b9e70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
        20  QuartzCore                          0x00000001122b9cee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
        21  QuartzCore                          0x00000001122ae475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
        22  QuartzCore                          0x00000001122dbc0a _ZN2CA11Transaction6commitEv + 486
        23  QuartzCore                          0x00000001122dc37c _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
        24  CoreFoundation                      0x000000010d48a947 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
        25  CoreFoundation                      0x000000010d48a8b7 __CFRunLoopDoObservers + 391
        26  CoreFoundation                      0x000000010d47fe2c CFRunLoopRunSpecific + 524
        27  UIKit                               0x000000010dd764f5 -[UIApplication _run] + 402
        28  UIKit                               0x000000010dd7b30d UIApplicationMain + 171
        29  Cycloid                             0x000000010d37be0d main + 109
        30  libdyld.dylib                       0x000000010fd8a92d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

解决方案

go to your storyboard, select the prototype cell, remove your custom class (so that is is a regular UITableViewCell again), build the project once, then set the custom class back to CustomTableViewCell and try again.

这篇关于CustomCell是SIGABRT错误[W / code]空或结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆