I have an app with a standard UIView that contains a toolbar. I am able to tap a button on the toolbar to open a UIActionSheet and am able to display my text there with no issues. What I’d like to do is have the action sheet items display a different XIB from my project. I have everything set up both in the relevant header and implementation files as well as the XIBs, but I need to link the action of tapping the action sheet item to displaying the second view.
This is what I have so far:
- (void)actionSheet:(UIActionSheet *)sheet willDissmissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex != [sheet cancelButtonIndex]) {
if (buttonIndex == 0) {
ABC *secondview = [[ABC alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:secondview animated:YES];
}
if (buttonIndex == 1) {
DEF *secondview = [[DEF alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:secondview animated:YES];
}
if (buttonIndex == 2) {
GHI *secondview = [[GHI alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:secondview animated:YES];
}
[self dismissModalViewControllerAnimated:YES];
};
}
This opens my action sheet and displays all the correct info, but tapping “ABC,” “DEF,” or “GHI” only closes the action sheet as though I’ve tapped the cancel button. How do I set it so tapping “ABC,” “DEF,” or “GHI” opens a different XIB in my project?
Start by fixing your method name: you have misspelled “dismiss”. If this is your actual code, the delegate method currently isn’t being called.
Follow-up:
OK, I tested your code (with or without the seemingly unnecessary dismissModalViewController…) and it works for me.
Which makes me think that there is something wrong with your larger setup. Have you set a breakpoint and made sure your code is actually getting run?
If it’s not getting run (which is my suspicion), check if you failed to pass the appropriate value for delegate: when you were setting up your UIActionSheet. (In particular, might you have passed nil as the delegate? This would cause a silent failure of the kind you are describing.)
Are you getting any warnings from the compiler/Clang?