1

i am creating a button using the following code:

[self addCenterButtonWithImage:[UIImage imageNamed:@"scan.png"]
 highlightImage:[UIImage imageNamed:@"scan_hover.png"]];

i need to connect this to a method. how do i do that? i am very new to ios development, so sorry if this is a stupid question.

would it be possible to load a view controller on clicking the button?( i have the code to be executed in the viewdidload method) basically this button is there to customise the tab bar to have the centre tab item jutting out...

s5v
  • 495
  • 5
  • 20
  • Did you see the documentation for `UIButton`? It inherits from `UIControl`, therefore it has an `addTarget:action:forControlEvents:` method. –  Jul 08 '13 at 13:41

1 Answers1

1

You can connect to a IBAction in interface builder

-(IBAction)someMethod:(id)sender{
}

You can connect programatically

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn addTarget:self action:@selector(someMethod:) forControlEvents:UIControlEventTouchUpInside];
  • thank you. used:[btn addTarget:self action:@selector(seguescan:) forControlEvents:UIControlEventTouchUpInside]; and it worked perfectly. still some problems- as i am trying to use xZing- and the scan takes the whole screen and the tabbar disappears, but the question i asked was cleared. – s5v Jul 10 '13 at 09:50