Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add target for UIButton - iOS [closed]

Tags:

ios

uibutton

Anyoone can help me on how to add action to call the following method using UIButton.

-(void)navigatePics:(id)sender andIndex:(NSInteger *)index{}
like image 273
Siddharthan Asokan Avatar asked Aug 13 '12 18:08

Siddharthan Asokan


1 Answers

Use the button.setTag:(NSInteger) method to add the index to the UIButton as a tag.

UIButton *button = ...;
[button setTag:1234];
[button addTarget:self action:@selector(navigatePics:) forControlEvents:UIControlEventTouchUpInside];

Then in navigatePics, read the tag.

-(void)navigatePics:(UIButton *)sender
{
 int index = sender.tag;
 // index = 1234;
}
like image 131
CSmith Avatar answered Sep 19 '22 14:09

CSmith