ios - Function for UIBarButtonItem -


i'm using core data , i'm making save button 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 error i'm getting:

2015-04-29 19:12:42.762 iknižnica[25716:11689183] -[ikniz_nica.pridatviewcontroller savetapped]: unrecognized selector sent instance 0x7ff5ab63ff50 2015-04-29 19:12:42.851 iknižnica[25716:11689183] * terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[ikniz_nica.pridatviewcontroller savetapped]: unrecognized selector sent 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 uncaught exception of type nsexception (lldb)

i posted source code here: http://pastebin.com/m9amakgr

problem not in button settings, in function

instead of:

func savetapped(){ 

should be:

func savetapped(sender:uibutton){ 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -