Monday, June 17, 2013

UIActionSheetDelegate actionSheetCancel example in Objective C (iOS).

UIActionSheetDelegate actionSheetCancel

Sent to the delegate before an action sheet is canceled.

- (void)actionSheetCancel:(UIActionSheet *)actionSheet

The action sheet that will be canceled.

Discussion of [UIActionSheetDelegate actionSheetCancel]
If the action sheet’s delegate does not implement this method, clicking the cancel button is simulated and the action sheet is dismissed. Implement this method if you need to perform some actions before an action sheet is canceled. An action sheet can be canceled at any time by the system—for example, when the user taps the Home button. The actionSheet:willDismissWithButtonIndex: and actionSheet:didDismissWithButtonIndex: methods are invoked after this method.

UIActionSheetDelegate actionSheetCancel example.
To be sure to receive the delegate calls of your UIActionSheet, be sure to indicate in your controller's interface declaration (.h):

@interface YourViewController : UIViewController<UIActionSheetDelegate>

Then in the controller's implementation (.m) :

- (void)actionSheetCancel:(UIActionSheet *)actionSheet {

    NSLog(@"action sheet is about to be cancelled");

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
    NSLog(@"action sheet was dismissed");

Example of [UIActionSheetDelegate actionSheetCancel].
-(void) showSheet:(UITabBar *)tabBar displayTitle:(NSString *)name{

    UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:name

   [menu showFromTabBar:tabBar];
   [menu setBounds:CGRectMake(0,0,320, 700)];


// actionsheet delegate protocol item
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex{

    NSLog(@"button index = %d", buttonIndex);

- (void)actionSheetCancel:(UIActionSheet *)actionSheet{

    NSLog(@"in action canceled method");

End of UIActionSheetDelegate actionSheetCancel example article.