I did something like this to customize an Action Sheet:
-(void) showPopup {
unitPicker *pc = [[unitPicker alloc] init];
UIActionSheet *popupQuery = [[UIActionSheet alloc]
initWithTitle:@"Units"
delegate:pc
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil
];
[pc setParent:self];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[popupQuery showInView:self.view];
[popupQuery setBounds:CGRectMake(0,0,320, 350)];
[pc setAs:popupQuery];
[popupQuery addSubview:pc.view];
}
The trick being that "unitPicker" was derived from a UIControllerView, but implemented the UIActionSheetDelegate protocol. It supplied the two functions:
- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex;
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex;
To deal with any cleanup. The big part was that the format of unitPicker was created from a NIB, as it would with any UIViewController.
The buttons in the view dismissed the actionSheet with the code in their touchUpInside handlers:
[as dismissWithClickedButtonIndex:0 animated:TRUE];
(You can see in the code above that "as" was set to be the actionSheet object).