Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Cameron Bourke
10,198 PointsOne UIActionSheet for multiple View Controllers
Hey everyone.
Basically I want to create an ActionSheet that is linked to a log out button that is used in more than one Viewcontroller. So instead of writing the code and copy and pasting it in each of the Viewcontroller's viewDidLoad, I can just write it once and link each button to it. This is to achieve easier and quicker maintenance.
I originally thought about putting the code for the ActionSheet in the delegate and linking it that way but that didn't seem to work. I've also had no luck searching for an answer on line.
Any help is appreciated!
2 Answers
Stone Preston
42,016 Pointscan you post the code you are putting in viewDidLoad?
Cameron Bourke
10,198 PointsSorry, I meant IB Action!
- (IBAction)logOut:(id)sender {
UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:
@"Log Out",
@"Support",
@"Rate this App",
nil];
popup.tag = 1;
[popup showInView:[UIApplication sharedApplication].keyWindow];
}
But yeah, instead of creating one of these in each viewcontroller.m, the aim is to have it once somewhere and all four viewcontrollers work from the one.