I have a simple view controller with a few buttons that are defined as IBActions. I want to place them on a scroll view, basically making the whole page scrollable (let’s say they are really big buttons and I have a bunch of them). How can I do that? I tried to add those buttons, but since they are defined as IBAction it did not work.
Here is some of my code. thanks!
- (IBAction) switchFromThird : (id)sender
{
//some action...
}
- (IBAction) BackHome : (id)sender
{
//some action...
}
- (void)viewDidLoad
{
[super viewDidLoad];
myScroll.contentSize = CGSizeMake(480, 1000);
myScroll.maximumZoomScale = 4.0;
myScroll.minimumZoomScale = 1.0;
myScroll.clipsToBounds = YES;
myScroll.delegate = self;
[myScroll addSubview:switchFromThird]; //???
[myScroll addSubview:BackHome]; //???
[myScroll release];
}
No, no, no.
Please read this article in iOS Developer Library. You can’t add a method (function) to a view! It’s like you wanted to have a computer program in your printed document on a sheet of paper!
You should do something like this:
IBOutlet UIButton *BackHomeButtonin your .h file.BackHomeButtonoutlet to your button[myScroll addSubview:BackHome];with[myScroll addSubview:BackHomeButton];.Then, and only then it will work. As I said: you can print only images and text, not computer programs!