Swift:崩溃app如果使用DropDown()

时间:2018-05-13 08:43:44

标签: ios swift dropdown

我使用此代码:

let amountDropDown = DropDown()
amountDropDown.anchorView = view
amountDropDown.dataSource = ["Car", "Motorcycle", "Truck"]

在午餐应用程序之后,我的应用程序崩溃了:

2018-05-12 17:45:18.946508+0430 Matap[47483:593732] Unknown class _TtC13DropDown_Demo12DropDownCell in Interface Builder file.
2018-05-12 17:45:18.965499+0430 Matap[47483:593732] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIView 0x7f9001d38760> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key optionLabel.'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010e19612b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010d82af41 objc_exception_throw + 48
    2   CoreFoundation                      0x000000010e196079 -[NSException raise] + 9
    3   Foundation                          0x000000010d249a63 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292
    4   UIKit                               0x000000010f097288 -[UIView(CALayerDelegate) setValue:forKey:] + 172
    5   UIKit                               0x000000010f457c2d -[UIRuntimeOutletConnection connect] + 109
    6   CoreFoundation                      0x000000010e1393cd -[NSArray makeObjectsPerformSelector:] + 317
    7   UIKit                               0x000000010f4565e3 -[UINib instantiateWithOwner:options:] + 1856
    8   Matap                               0x000000010cea3e51 _T08DropDownAAC12fittingWidth33_7BE2DBF176694C4708972467648CE159LL12CoreGraphics7CGFloatVyF + 785
    9   Matap                               0x000000010cea67e8 _T08DropDownAAC39constraintWidthToFittingSizeIfNecessary33_7BE2DBF176694C4708972467648CE159LLy12CoreGraphics7CGFloatV1x_AG1yAG5widthAG15offscreenHeighttz6layout_tF + 216
    10  Matap                               0x000000010cea2d3b _T08DropDownAAC13computeLayout33_7BE2DBF176694C4708972467648CE159LL12CoreGraphics7CGFloatV1x_AG1yAG5widthAG15offscreenHeightAG07visibleN0Sb14canBeDisplayedAB9DirectionOANtyF + 2651
    11  Matap                               0x000000010cea08e7 _T08DropDownAAC17updateConstraintsyyF + 215
    12  Matap                               0x000000010cea3554 _T08DropDownAAC17updateConstraintsyyFTo + 36
    13  UIKit                               0x000000010fb46878 -[UIView(AdditionalLayoutSupport) _sendUpdateConstraintsIfNecessaryForSecondPass:] + 161
    14  UIKit                               0x000000010fb46e94 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 1296
    15  UIKit                               0x000000010fb476c5 __100-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:]_block_invoke + 90
    16  UIKit                               0x000000010fb47234 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:] + 160
    17  Matap                               0x000000010ce9fa6b _T08DropDownAAC5setup33_7BE2DBF176694C4708972467648CE159LLyyFyycfU_ + 43
    18  Matap                               0x000000010ceb10d2 _T08DropDownAAC5setup33_7BE2DBF176694C4708972467648CE159LLyyFyycfU_TA + 50
    19  Matap                               0x000000010ce6e2c9 _T0Ix_IyB_TR + 41
    20  libdispatch.dylib                   0x0000000112ff12f7 _dispatch_call_block_and_release + 12
    21  libdispatch.dylib                   0x0000000112ff233d _dispatch_client_callout + 8
    22  libdispatch.dylib                   0x0000000112ffd5f9 _dispatch_main_queue_callback_4CF + 628
    23  CoreFoundation                      0x000000010e158e39 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    24  CoreFoundation                      0x000000010e11d462 __CFRunLoopRun + 2402
    25  CoreFoundation                      0x000000010e11c889 CFRunLoopRunSpecific + 409
    26  GraphicsServices                    0x000000011538b9c6 GSEventRunModal + 62
    27  UIKit                               0x000000010efc65d6 UIApplicationMain + 159
    28  Matap                               0x000000010ce83fa7 main + 55
    29  libdyld.dylib                       0x000000011306ed81 start + 1
    30  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

我认为崩溃的原因是这一行:let amountDropDown = DropDown()

另外,我import DropDown进入我的快速代码

此插件:DropDown

代码:

import UIKit
import DropDown

class ViewControllerHandle: UIViewController {
    @IBOutlet var viewMain: UIView!
    @IBOutlet weak var backBoard: UIView!
    @IBOutlet weak var secondGo: UIView!
    @IBOutlet weak var thirdGo: UIView!
    @IBOutlet weak var firstGo: UIView!
    @IBOutlet weak var goToSecond: UIView!
    @IBOutlet weak var firstView: UIView!

    /* BOX GENDER */
    @IBOutlet weak var boxGender: UIView!
    @IBOutlet weak var genderSelect: UIView!

    @IBOutlet weak var pickerGender: UIPickerView!
    @IBOutlet weak var textPickerGender: UILabel!

    /* BOX EX */
    @IBOutlet weak var boxEx: UIView!
    @IBOutlet weak var exSelect: UIView!

    /* BOX EMERGENCY */
    @IBOutlet weak var boxEmergency: UIView!
    @IBOutlet weak var emergencySelect: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let backBoardGesture = UITapGestureRecognizer(target: self, action: #selector(handleBackBoard(sender:)))
        backBoard.addGestureRecognizer(backBoardGesture)

        let goToSecondGesture = UITapGestureRecognizer(target: self, action: #selector(handleGoToSecond(sender:)))
        goToSecond.addGestureRecognizer(goToSecondGesture)

        let setBG = SetBackground()
        setBG.addGradient(viewMain: viewMain)

        secondGo.layer.cornerRadius = 45
        thirdGo.layer.cornerRadius = 45
        firstGo.layer.cornerRadius = 45
        goToSecond.layer.cornerRadius = 20

        boxGender.layer.cornerRadius = 25
        genderSelect.layer.cornerRadius = 20

        boxEx.layer.cornerRadius = 25
        exSelect.layer.cornerRadius = 20

        boxEmergency.layer.cornerRadius = 25
        emergencySelect.layer.cornerRadius = 20

        let amountDropDown = DropDown()
    }

    @objc func handleGoToSecond(sender: UITapGestureRecognizer) {
        let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let homeViewController: UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "ViewControllerMenu")
        self.present(homeViewController, animated: true, completion: nil)
    }

    @objc func handleBackBoard(sender: UITapGestureRecognizer) {
        dismiss(animated: true, completion: nil)
    }
}

1 个答案:

答案 0 :(得分:1)

您是否创建了自定义单元格,它是DropDownCell的子类? 如果是这样,此链接可能会有所帮助:https://github.com/AssistoLab/DropDown#custom-cell

optionLabel是DropDownCell的属性。

open class DropDownCell: UITableViewCell {

    //UI
    @IBOutlet open weak var optionLabel: UILabel!

    var selectedBackgroundColor: UIColor?
}

ReadMe链接说:

  

至少在你的xib中有一个标签链接到代码中的optionLabel IBOutlet(optionLabel是DropDownCell的属性)