简体   繁体   中英

Unrecognized Selector Swift 2 Purelayout Xcode7

Hello having an issue with an unrecognized selector sent to an instance exception I have searched around a bit but I've been unable to find a solution.

The error I believe is occurring in my use of PureLayout but still unsure of what is specifically causing the issue. One weird thing is that after using Carthage to make my purelayout framework I had to use a weird bridging header in order to import purelayout usually you import PureLayout.h but my code would not compile unless I imported PureLayout_Ios/Purelayout.h in my bridging header. And so I have to import PureLayout_iOS in my viewcontroller.

View:

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()
}

And here is the error stack trace:

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) 

thank you guys!

Try replacing this line...

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

with this instead...

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

You can find more info in the apple document here: Objective C Selectors

使用迦太基更新我的purelayout库后,它已修复,但不确定是什么问题,这是github上的最新changlog

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM