Let’s say I have this code:
if ([resultButton.titleLabel.text isEqualToString:@"Tax"]) {
TAXViewController *controller = [[TAXViewController alloc]initWithNibName:@"TAXViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:controller animated:YES completion:nil];
[controller release];
}else if ([resultButton.titleLabel.text isEqualToString:@""]){
RENTViewController *controller = [[RENTViewController alloc]initWithNibName:@"RENTViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:controller animated:YES completion:nil];
[controller release];
}else if //repeats a lot......
And I want to use this same exact code in multiple .h files. Is there a way to write the code (in only one place) and access it from other .h files without having it repeat everywhere?
So in the end I guess, I could just pass a string to that other .h/.m files and it would open the view with the matching string.
Put it in one class and make all of the other files you want to access it in a subclass of it.
You can also WAY simplify your code