NSInvalidArgumentException Using UISegmentedControl - ios

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)

Related

Swift Swipe gesture recognizer crashes program [duplicate]

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.

Thread:1 Signal SIGAGBRT

Why do I get a Thread:1 Signal SIGAGBRT within this code? I don't know what to change to fix the error. The application starts and as soon as I press the button the app cancels out and gives me an error.
import UIKit
class ViewController: UIViewController {
#IBOutlet var textFieldInput: UITextField!
#IBOutlet var laCelsius: UILabel!
#IBOutlet var laFahrenheit: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func btn(sender: UIButton) {
var c_out = 0.0
var f_out = 0.0
var inputValue = 0.0
let textInput = NSString(string: textFieldInput.text!)
inputValue = textInput.doubleValue
c_out = (inputValue-32)*5/9
f_out = inputValue * 1.8 + 32
self.laCelsius.text = NSString(format: "%3.2f" ,c_out) as String
self.laFahrenheit.text = NSString(format: "%3.2f" ,f_out) as String
}
}
this is the error code:
2016-09-22 14:15:51.669 DegreeCL[19045:1774964] -[DegreeCL.ViewController btnPressed:]: unrecognized selector sent to instance 0x7fa7bb643d40
2016-09-22 14:15:51.674 DegreeCL[19045:1774964] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DegreeCL.ViewController btnPressed:]: unrecognized selector sent to instance 0x7fa7bb643d40'
*** First throw call stack:
(
0 CoreFoundation 0x000000010de1dd85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010fbc1deb objc_exception_throw + 48
2 CoreFoundation 0x000000010de26d3d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010dd6ccfa ___forwarding___ + 970
4 CoreFoundation 0x000000010dd6c8a8 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010e647a8d -[UIApplication sendAction:to:from:forEvent:] + 92
6 UIKit 0x000000010e7bae67 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x000000010e7bb143 -[UIControl _sendActionsForEvents:withEvent:] + 327
8 UIKit 0x000000010e7ba263 -[UIControl touchesEnded:withEvent:] + 601
9 UIKit 0x000000010e6ba99f -[UIWindow _sendTouchesForEvent:] + 835
10 UIKit 0x000000010e6bb6d4 -[UIWindow sendEvent:] + 865
11 UIKit 0x000000010e666dc6 -[UIApplication sendEvent:] + 263
12 UIKit 0x000000010e640553 _UIApplicationHandleEventQueue + 6660
13 CoreFoundation 0x000000010dd43301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x000000010dd3922c __CFRunLoopDoSources0 + 556
15 CoreFoundation 0x000000010dd386e3 __CFRunLoopRun + 867
16 CoreFoundation 0x000000010dd380f8 CFRunLoopRunSpecific + 488
17 GraphicsServices 0x00000001124b3ad2 GSEventRunModal + 161
18 UIKit 0x000000010e645f09 UIApplicationMain + 171
19 DegreeCL 0x000000010dc38412 main + 114
20 libdyld.dylib 0x000000011068592d start + 1
21 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The crucial information is
[DegreeCL.ViewController btnPressed:]: unrecognized selector sent to instance ...'
That means in Interface Builder there is somewhere a dead connection to an action btnPressed. Remove it.
You can search for btnPressed with ⇧⌘F.
SIGABRIT - signal is sent due to many reasons but in this case i think you have problem with Memory.
You should turn on All Exeptions with option of po $arg1 it will identify the error.
Select your button from interface builder, then select connection inspector from utilities and check that if you have extra connected action method should be there, remove it by clicking x and your issue will be solved!
It's should be btnPressed as per your crash log!

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