cdub
cdub

Reputation: 25701

Grabbed the action of a UIBarButtonItem

I have code like this in my navigation bar:

UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStylePlain target:self action:@selector(self)];

self.navigationItem.rightBarButtonItem = myButton;

What's the next step to grab when this is actually pressed?

Upvotes: 0

Views: 67

Answers (2)

Shankar BS
Shankar BS

Reputation: 8402

Do like this


   UIBarButtonItem *Button=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(myAction:)];
   self.navigationItem.leftBarButtonItem=Button;


 - (void)myAction:(id)sender
    {
        //do ur actions 
    }


Upvotes: 2

Tarek Hallak
Tarek Hallak

Reputation: 18470

You mad a mistake here by setting @selector(self).

You need to put here the actual function you need to fire:

UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStylePlain target:self action:@selector(doSomeThing)];

And of course:

- (void) doSomeThing{

}

Upvotes: 2

Related Questions