Swift Swipe gesture recognizer crashes program [duplicate] - ios

This question already has answers here:
UISwipeGestureRecognizer throw unrecognised selector sent error
(2 answers)
Closed 5 years ago.
Hello I added a swift gesture recognizer and it keeps crashing my program
override func viewDidLoad() {
super.viewDidLoad()
let leftSwipe = UISwipeGestureRecognizer(target: self, action: Selector(("handleSwipes:")))
let rightSwipe = UISwipeGestureRecognizer(target: self, action: Selector(("handleSwipes:")))
leftSwipe.direction = .left
rightSwipe.direction = .right
self.view.addGestureRecognizer(leftSwipe)
self.view.addGestureRecognizer(rightSwipe)
}
func handleSwipes(sender: UISwipeGestureRecognizer) {
if (sender.direction == .left ) {
headerLabel.text = "Zodiac Yearly"
}
if (sender.direction == .right ) {
headerLabel.text = "Characteristics"
}
}
This is the error I am getting
2017-09-08 20:17:33.355 Views[40942:2309262] -[Views.ViewController handleSwipes:]: unrecognized selector sent to instance 0x7fdd9bc0dc90
2017-09-08 20:17:33.361 Views[40942:2309262] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Views.ViewController handleSwipes:]: unrecognized selector sent to instance 0x7fdd9bc0dc90'
*** First throw call stack:
(
0 CoreFoundation 0x0000000111f40b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010f1e6141 objc_exception_throw + 48
2 CoreFoundation 0x0000000111fb0134 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x0000000111ec7840 ___forwarding___ + 1024
4 CoreFoundation 0x0000000111ec73b8 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010fbecf59 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 57
6 UIKit 0x000000010fbf4d57 _UIGestureRecognizerSendTargetActions + 109
7 UIKit 0x000000010fbf270b _UIGestureRecognizerSendActions + 225
8 UIKit 0x000000010fbf19ce -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 981
9 UIKit 0x000000010fbde152 _UIGestureEnvironmentUpdate + 1219
10 UIKit 0x000000010fbddc43 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 484
11 UIKit 0x000000010fbdce0a -[UIGestureEnvironment _updateGesturesForEvent:window:] + 274
12 UIKit 0x000000010f728eea -[UIWindow sendEvent:] + 4092
13 UIKit 0x000000010f6d5a84 -[UIApplication sendEvent:] + 352
14 UIKit 0x000000010feb95d4 __dispatchPreprocessedEventFromEventQueue + 2926
15 UIKit 0x000000010feb1532 __handleEventQueue + 1122
16 CoreFoundation 0x0000000111ee6c01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
17 CoreFoundation 0x0000000111ecc0cf __CFRunLoopDoSources0 + 527
18 CoreFoundation 0x0000000111ecb5ff __CFRunLoopRun + 911
19 CoreFoundation 0x0000000111ecb016 CFRunLoopRunSpecific + 406
20 GraphicsServices 0x0000000113ed7a24 GSEventRunModal + 62
21 UIKit 0x000000010f6b8134 UIApplicationMain + 159
22 Views 0x000000010ec06a67 main + 55
23 libdyld.dylib 0x0000000112f6c65d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipes(sender:)))
#objc func handleSwipes(sender: UISwipeGestureRecognizer) {
// ...
}
This should work in Swift 3 and 4.

Related

swift Turn a generated imageView into a UIButton in code

I am trying to add a tap gesture to a generated Image and it works ok but keeps crashing the program once I click on the image. What did I do wrong here. Any help is appreciated.
let tapGesture = UITapGestureRecognizer(target: self, action: "image Tapped")
let imageView = UIImageView(image: UIImage(data: data));
imageView.addGestureRecognizer(tapGesture)
imageView.userInteractionEnabled = true
This is the error I get
2016-07-12 09:19:30.241 XXX[2170:27661] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ‘-[MyViewController image Tapped]: unrecognized selector sent to instance 0x7fe811e30560'
*** First throw call stack:
(
0 CoreFoundation 0x000000010e2a7d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000011144ddeb objc_exception_throw + 48
2 CoreFoundation 0x000000010e2b0d3d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010e1f6cfa ___forwarding___ + 970
4 CoreFoundation 0x000000010e1f68a8 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000110391b28 _UIGestureRecognizerSendTargetActions + 153
6 UIKit 0x000000011038e19a _UIGestureRecognizerSendActions + 162
7 UIKit 0x000000011038c197 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 843
8 UIKit 0x0000000110394655 ___UIGestureRecognizerUpdate_block_invoke898 + 79
9 UIKit 0x00000001103944f3 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 342
10 UIKit 0x0000000110381e75 _UIGestureRecognizerUpdate + 2634
11 UIKit 0x000000010ff0e48e -[UIWindow _sendGesturesForEvent:] + 1137
12 UIKit 0x000000010ff0f6c4 -[UIWindow sendEvent:] + 849
13 UIKit 0x000000010febadc6 -[UIApplication sendEvent:] + 263
14 UIKit 0x000000010fe94553 _UIApplicationHandleEventQueue + 6660
15 CoreFoundation 0x000000010e1cd301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
16 CoreFoundation 0x000000010e1c322c __CFRunLoopDoSources0 + 556
17 CoreFoundation 0x000000010e1c26e3 __CFRunLoopRun + 867
18 CoreFoundation 0x000000010e1c20f8 CFRunLoopRunSpecific + 488
19 GraphicsServices 0x0000000112d68ad2 GSEventRunModal + 161
20 UIKit 0x000000010fe99f09 UIApplicationMain + 171
21 ApivitaClient 0x000000010d6a1482 main + 114
22 libdyld.dylib 0x0000000111f1192d start + 1
23 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
replace
let tapGesture = UITapGestureRecognizer(target: self, action: "image Tapped")
with
let tapGesture = UITapGestureRecognizer(target:self, action: #selector(imageTapped))
and create func imageTapped() {}
The action part in the UITapGestureRecognizer initializer means which method will be executed. And the action part means who's responsible for that action, who's the delegate.
Use this to initialize the gesture recognizer:
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: Selector("imageTapped:"))
Please note the colon : after the name of the method (imageTapped). This means the gesture recognizer will call the imageTapped method and pass the sender parameter, which it will be useful if you want to determine which gesture recognizer was triggered. This is really useful if you have several images that can be tapped, so you don't have to build a method for each one.
Then you need to declare the imageTapped method:
func imageTapped(sender: UIGestureRecognizer) {
print("Image tapped")
}
You can declare the function to work without parameter as well, just declare the function without the sender parameter and delete the colon in the action selector. Anyway, I recommend to keep it, it may be useful somewhere and it's better if you learn it that way.

NSInvalidArgumentException Using UISegmentedControl

I am creating an application and receiving an NSInvalidArgumentException. The error occurs when I run my application on the iOS emulator and click on one of the items in the UISegmentedControl.
I believe it relates to my "mapTypeChanged" method but I wanted to confirm:
Code:
import UIKit
import MapKit
class MapViewController : UIViewController {
var mapView: MKMapView!
//called if the view property of a ViewController is nill
override func loadView() {
//Create a map view
mapView = MKMapView()
//Set it as the "View" of the ViewController
view = mapView
let segmentedControl = UISegmentedControl(items: ["Standard", "Hybrid", "Satellite"])
segmentedControl.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.5)
segmentedControl.selectedSegmentIndex = 0
segmentedControl.addTarget(self, action: "mapTypeChanged:", forControlEvents: .ValueChanged)
segmentedControl.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(segmentedControl)
let topConstraint = segmentedControl.topAnchor.constraintEqualToAnchor(topLayoutGuide.bottomAnchor, constant: 8)
let margins = view.layoutMarginsGuide
let leadingConstraint = segmentedControl.leadingAnchor.constraintEqualToAnchor(margins.leadingAnchor)
let trailingConstraint = segmentedControl.trailingAnchor.constraintEqualToAnchor(margins.trailingAnchor)
topConstraint.active = true
leadingConstraint.active = true
trailingConstraint.active = true
}
func mapTypedChanged(segControl: UISegmentedControl){
switch segControl.selectedSegmentIndex{
case 0:
mapView.mapType = .Standard
case 1:
mapView.mapType = .Hybrid
case 2:
mapView.mapType = .Satellite
default:
break
}
}
override func viewDidLoad() {
super.viewDidLoad()
print("MapViewController loaded its view")
}
}
Error:
ConversionViewController loaded its view
MapViewController loaded its view
2016-04-26 13:54:56.341 WorldTrotter[1530:865418] -[WorldTrotter.MapViewController mapTypeChanged:]: unrecognized selector sent to instance 0x7fb883c8dce0
2016-04-26 13:54:56.344 WorldTrotter[1530:865418] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WorldTrotter.MapViewController mapTypeChanged:]: unrecognized selector sent to instance 0x7fb883c8dce0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000102281f45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000103fa5deb objc_exception_throw + 48
2 CoreFoundation 0x000000010228a56d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001021d7eea ___forwarding___ + 970
4 CoreFoundation 0x00000001021d7a98 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000102a9fe91 -[UIApplication sendAction:to:from:forEvent:] + 92
6 UIKit 0x0000000102c0b4d8 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x0000000102c0b7a4 -[UIControl _sendActionsForEvents:withEvent:] + 311
8 UIKit 0x0000000102cb8661 -[UISegmentedControl _setSelectedSegmentIndex:notify:animate:] + 690
9 UIKit 0x0000000102cbad35 -[UISegmentedControl touchesEnded:withEvent:] + 232
10 UIKit 0x0000000102b0ded1 -[UIWindow _sendTouchesForEvent:] + 835
11 UIKit 0x0000000102b0ec06 -[UIWindow sendEvent:] + 865
12 UIKit 0x0000000102abe2fa -[UIApplication sendEvent:] + 263
13 UIKit 0x0000000102a98abf _UIApplicationHandleEventQueue + 6844
14 CoreFoundation 0x00000001021ae011 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15 CoreFoundation 0x00000001021a3f3c __CFRunLoopDoSources0 + 556
16 CoreFoundation 0x00000001021a33f3 __CFRunLoopRun + 867
17 CoreFoundation 0x00000001021a2e08 CFRunLoopRunSpecific + 488
18 GraphicsServices 0x0000000106b11ad2 GSEventRunModal + 161
19 UIKit 0x0000000102a9e30d UIApplicationMain + 171
20 WorldTrotter 0x0000000101debdcd main + 109
21 libdyld.dylib 0x00000001073e592d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
In addTarget you wrote mapTypeChanged, but the function is called mapTypedChanged (notice "Type" vs "Typed").
Instead of
func mapTypedChanged(segControl: UISegmentedControl)
, use the correct
func mapTypeChanged(segControl: UISegmentedControl)

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
After using carthage to update my purelayout library it was fixed, not sure what the issue was though, here is the latest changlog on github.

"terminating with uncaught exception of type NSException" in Swift

When I click on a button the app just crashes and I get this error:
2015-06-12 19:33:16.150 scroll view[79136:11092579] -[scroll_view.ViewController Action:]: unrecognized selector sent to instance 0x7f834148bdd0
2015-06-12 19:33:16.153 scroll view[79136:11092579] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[scroll_view.ViewController Action:]: unrecognized selector sent to instance 0x7f834148bdd0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000103766c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001052d1bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010376e0ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001036c413c ___forwarding___ + 988
4 CoreFoundation 0x00000001036c3cd8 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000104006da2 -[UIApplication sendAction:to:from:forEvent:] + 75
6 UIKit 0x000000010411854a -[UIControl _sendActionsForEvents:withEvent:] + 467
7 UIKit 0x0000000104117919 -[UIControl touchesEnded:withEvent:] + 522
8 UIKit 0x00000001043b1a10 _UIGestureRecognizerUpdate + 9487
9 UIKit 0x0000000104053686 -[UIWindow _sendGesturesForEvent:] + 1041
10 UIKit 0x00000001040542b2 -[UIWindow sendEvent:] + 666
11 UIKit 0x000000010401a581 -[UIApplication sendEvent:] + 246
12 UIKit 0x0000000104027d1c _UIApplicationHandleEventFromQueueEvent + 18265
13 UIKit 0x00000001040025dc _UIApplicationHandleEventQueue + 2066
14 CoreFoundation 0x000000010369a431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15 CoreFoundation 0x00000001036902fd __CFRunLoopDoSources0 + 269
16 CoreFoundation 0x000000010368f934 __CFRunLoopRun + 868
17 CoreFoundation 0x000000010368f366 CFRunLoopRunSpecific + 470
18 GraphicsServices 0x000000010774da3e GSEventRunModal + 161
19 UIKit 0x0000000104005900 UIApplicationMain + 1282
20 scroll view 0x000000010356ac67 main + 135
21 libdyld.dylib 0x0000000105a29145 start + 1
22 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Here is my code:
var imageView: UIImageView!
var scrollView: UIScrollView!
var containerView = UIView()
var buttonScroll: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// 1
imageView = UIImageView(image: UIImage(named: "Map 1.png"))
// 2
scrollView = UIScrollView(frame: view.bounds)
scrollView.backgroundColor = UIColor.blackColor()
// 3
scrollView.contentSize = imageView.bounds.size
// 4
scrollView.addSubview(imageView)
view.addSubview(scrollView)
scrollView.contentSize.height = scrollView.frame.size.height
var lvl1button = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton
lvl1button.frame = CGRectMake(250, 140, 100, 50)
let level1 = UIImage(named: "Lvl 1 Button.png") as UIImage!
lvl1button.setImage(level1, forState: .Normal)
lvl1button.addTarget(self, action: "Action:", forControlEvents: UIControlEvents.TouchUpInside)
scrollView.addSubview(lvl1button)
You are setting up your button with an action selector called "Action:".
lvl1button.addTarget(self, action: "Action:", forControlEvents: UIControlEvents.TouchUpInside)
But self, your view controller, has no such method so when Cocoa tries to call it on button-press, you crash. Unfortunately you did not show that part of your code so one can only guess, but there could be a lot a reasons for this mismatch: the colon could be wrong, the spelling or capitalization could be wrong, and so on. Or maybe you just forgot to write the method!

Function for UIBarButtonItem

I'm using Core Data and I'm making a save button with this code:
self.navigationItem.setRightBarButtonItem(UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: Selector("saveTapped")), animated: true)
The save function:
func saveTapped(){
if (cell!.textField.text.isEmpty) {
let alert = UIAlertView()
alert.title = "Nevyplnené údaje"
alert.message = "Musíš vyplniť všetky údaje o knihe."
alert.addButtonWithTitle("Ok")
alert.show()
}
let appDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let obsah: NSManagedObjectContext = appDel.managedObjectContext!
let entity = NSEntityDescription.entityForName("List", inManagedObjectContext: obsah)
var pridat = Model(entity: entity! , insertIntoManagedObjectContext: obsah)
pridat.kniha = cell!.textField.text
pridat.autor = cell!.textField.text
pridat.rok = cell!.textField.text
pridat.vydavatelstvo = cell!.textField.text
pridat.strany = cell!.textField.text
obsah.save(nil)
}
This is the error I'm getting:
2015-04-29 19:12:42.762 iKnižnica[25716:11689183]
-[iKniz_nica.PridatViewController saveTapped]: unrecognized selector sent to instance 0x7ff5ab63ff50 2015-04-29 19:12:42.851
iKnižnica[25716:11689183] * Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason:
'-[iKniz_nica.PridatViewController saveTapped]: unrecognized selector
sent to instance 0x7ff5ab63ff50'
* First throw call stack: ( 0 CoreFoundation 0x0000000100bccc65 exceptionPreprocess + 165 1 libobjc.A.dylib
0x0000000102737bb7 objc_exception_throw + 45 2 CoreFoundation
0x0000000100bd40ad -[NSObject(NSObject) doesNotRecognizeSelector:] +
205 3 CoreFoundation 0x0000000100b2a13c
___forwarding_ + 988 4 CoreFoundation 0x0000000100b29cd8 _CF_forwarding_prep_0 + 120 5 UIKit
0x000000010146cda2 -[UIApplication sendAction:to:from:forEvent:] + 75
6 UIKit 0x000000010146cda2
-[UIApplication sendAction:to:from:forEvent:] + 75 7 UIKit 0x000000010157e54a -[UIControl _sendActionsForEvents:withEvent:] + 467
8 UIKit 0x000000010157d919
-[UIControl touchesEnded:withEvent:] + 522 9 UIKit 0x00000001014b9998 -[UIWindow _sendTouchesForEvent:] + 735 10 UIKit
0x00000001014ba2c2 -[UIWindow sendEvent:] + 682 11 UIKit
0x0000000101480581 -[UIApplication sendEvent:] + 246 12 UIKit
0x000000010148dd1c _UIApplicationHandleEventFromQueueEvent + 18265 13
UIKit 0x00000001014685dc
_UIApplicationHandleEventQueue + 2066 14 CoreFoundation 0x0000000100b00431
CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 15 CoreFoundation 0x0000000100af62fd
__CFRunLoopDoSources0 + 269 16 CoreFoundation 0x0000000100af5934 __CFRunLoopRun + 868 17 CoreFoundation
0x0000000100af5366 CFRunLoopRunSpecific + 470 18 GraphicsServices
0x0000000104bb3a3e GSEventRunModal + 161 19 UIKit
0x000000010146b900 UIApplicationMain + 1282 20 iKnizÃånica
0x00000001005c6377 main + 135 21 libdyld.dylib
0x0000000102e8f145 start + 1 ) libc++abi.dylib: terminating with
uncaught exception of type NSException (lldb)
I posted the source code here: http://pastebin.com/M9AMakGr
Problem is not in the button settings, but in function
Instead of:
func saveTapped(){
Should be:
func saveTapped(sender:UIButton){
Change your setRightBarButtonItem code to below code:
self.navigationItem.setRightBarButtonItem(UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: "saveTapped:"), animated: true)
In swift, for selector you just need to type the name of the function, that's it! Hope it helps

Resources