Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set an action for an UIBarButtonItem?

I try to set an action for an UIBarButtonItem like I did before with a normal button:

  1. Select the UIBarButtonItem in storyboard.
  2. Right-Click and pull to my .h-file
  3. Change to action and choose UIBarButtonItem and give the action a name.

        - (IBAction)haupt:(UIBarButtonItem *)sender;
    
  4. Write some code in the function at my .m-file.

    - (IBAction)haupt:(UIBarButtonItem *)sender {
        NSLog(@"button");
    
    
        }
    

Now I try this in the simulator, but nothing happens (No output on the console). What I am doing wrong?

like image 617
basti12354 Avatar asked Aug 04 '14 12:08

basti12354


1 Answers

Select the UIBarButton , Create an IBAction by CNRL+Dragging at the implementation section in .m file then try to print with NSLog use breakpoint to know if the control is reaching the IBAction you created.

like image 66
codeIgnitor Avatar answered Sep 27 '22 18:09

codeIgnitor