簡體   English   中英

無法識別的選擇器Swift 2 Purelayout Xcode7

[英]Unrecognized Selector Swift 2 Purelayout Xcode7

您好,無法識別的選擇器發送到實例異常時遇到了問題,我已經搜索了一下,但是找不到解決方案。

我相信我在使用PureLayout時會發生該錯誤,但仍不確定是什么引起了該問題。 一件奇怪的事情是,在使用迦太基制作我的purelayout框架之后,我必須使用一個奇怪的橋接頭來導入purelayout,通常您需要導入PureLayout.h,但是除非我在橋接頭中導入PureLayout_Ios / Purelayout.h,否則我的代碼將無法編譯。 。 因此,我必須在我的viewcontroller中導入PureLayout_iOS。

視圖:

var presenter: SignUpPresenterProtocol?
//lazy var logoImageView: UIImageView = UIImageView()
lazy var nextButton: UIButton = {
    var button = UIButton()
    button.backgroundColor = Styles.BUTTON_COLOR
    return button
}()

override func viewDidLoad() {
    super.viewDidLoad()
    self.setupSubviews()
    self.setupConstraints()
    self.setNeedsStatusBarAppearanceUpdate()
    self.presenter?.viewDidLoad()
}

private func setupSubviews()
{
    self.view.addSubview(self.nextButton)
    self.view.addSubview(self.userNameTextField)
    self.nextButton.addTarget(self, action: Selector("userDidSelectNext:"), forControlEvents: UIControlEvents.TouchUpInside)
    //self.view.addSubview(self.logoImageView)
}

private func setupConstraints()
{
    self.nextButton.translatesAutoresizingMaskIntoConstraints = false
    self.nextButton.autoMatchDimension(.Width, toDimension: .Width, ofView: self.view, withMultiplier: 0.8)
    self.nextButton.autoSetDimension(.Height, toSize: Styles.BUTTON_HEIGHT)
    self.nextButton.autoCenterInSuperview()x
}

func userDidSelectNext(sender: AnyObject)
{
    self.presenter?.userDidSelectNext()
}

這是錯誤堆棧跟蹤:

2015-07-28 08:51:58.218 app[10795:507285] -[UIButton autoMatchDimension:toDimension:ofView:withMultiplier:]: unrecognized selector sent to instance 0x7f9d02f8cad0
2015-07-28 08:51:58.222 app[10795:507285] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIButton autoMatchDimension:toDimension:ofView:withMultiplier:]: unrecognized selector sent to instance 0x7f9d02f8cad0'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001079e18b5 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001095c1df3 objc_exception_throw + 48
    2   CoreFoundation                      0x00000001079e9ead -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x000000010793819a ___forwarding___ + 970
    4   CoreFoundation                      0x0000000107937d48 _CF_forwarding_prep_0 + 120
    5   app                             0x0000000107324984 _TFC7app12UsernameViewP33_A6105A8D44322785BCD6FD80914CAE7C16setupConstraintsfS0_FT_T_ + 180
    6   app                             0x000000010732422d _TFC7app12UsernameView11viewDidLoadfS0_FT_T_ + 93
    7   app                             0x0000000107324312 _TToFC7app12UsernameView11viewDidLoadfS0_FT_T_ + 34
    8   UIKit                               0x000000010837fa6e -[UIViewController loadViewIfRequired] + 860
    9   UIKit                               0x000000010837fdbd -[UIViewController view] + 27
    10  UIKit                               0x00000001082607e4 -[UIWindow addRootViewControllerViewIfPossible] + 61
    11  UIKit                               0x0000000108260ee1 -[UIWindow _setHidden:forced:] + 302
    12  UIKit                               0x00000001082726fc -[UIWindow makeKeyAndVisible] + 43
    13  app                             0x0000000107326afc _TFC7app11AppDelegate11applicationfS0_FTCSo13UIApplication29didFinishLaunchingWithOptionsGSqGVSs10DictionaryCSo8NSObjectPSs9AnyObject____Sb + 588
    14  app                             0x0000000107326c43 _TToFC7app11AppDelegate11applicationfS0_FTCSo13UIApplication29didFinishLaunchingWithOptionsGSqGVSs10DictionaryCSo8NSObjectPSs9AnyObject____Sb + 179
    15  UIKit                               0x00000001081f2bc4 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 272
    16  UIKit                               0x00000001081f3cea -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3287
    17  UIKit                               0x00000001081f9e97 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1755
    18  UIKit                               0x00000001081f7635 -[UIApplication workspaceDidEndTransaction:] + 188
    19  FrontBoardServices                  0x000000010c2b0b5e -[FBSSerialQueue _performNext] + 192
    20  FrontBoardServices                  0x000000010c2b0ecc -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    21  CoreFoundation                      0x000000010790e171 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    22  CoreFoundation                      0x000000010790409c __CFRunLoopDoSources0 + 556
    23  CoreFoundation                      0x0000000107903553 __CFRunLoopRun + 867
    24  CoreFoundation                      0x0000000107902f68 CFRunLoopRunSpecific + 488
    25  UIKit                               0x00000001081f6fd2 -[UIApplication _run] + 402
    26  UIKit                               0x00000001081fb6f8 UIApplicationMain + 171
    27  app                             0x0000000107327e0d main + 109
    28  libdyld.dylib                       0x000000010a5f892d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

感謝大伙們!

嘗試更換這條線...

 self.nextButton.addTarget(self, action: Selector("userDidSelectNext:"), forControlEvents: UIControlEvents.TouchUpInside)

與此相反...

 self.nextButton.addTarget(self, action: "userDidSelectNext:", forControlEvents: UIControlEvents.TouchUpInside)

您可以在以下Apple文檔中找到更多信息: Objective C選擇器

使用迦太基更新我的purelayout庫后,它已修復,但不確定是什么問題,這是github上的最新changlog

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM