Pressing Cancel button doesn't retract

Discussion in 'iOS Programming' started by StefanDevil, Aug 23, 2010.

  1. macrumors member

    Joined:
    Jul 31, 2010
    #1
    Hi there,

    i implement an actionsheet, when press "ok" button, do these, press "cancel" go back. the "ok" button is working fine, but when i press the "cancel" button, nothing happens, it doesnt retract or do anything, just hang at the actionsheet view.

    below is my code:

    create button at nav bar:

    Code:
    
    	UIBarButtonItem *clearButton = [[[UIBarButtonItem alloc] initWithTitle:@"Clear History"
    																   style:UIBarButtonItemStyleBordered
    																  target:self
    																  action:@selector(ClearHistoryAction:)] autorelease];
    	self.navigationItem.leftBarButtonItem = clearButton;
    
    when click, launch action sheet:
    Code:
    
    - (IBAction)ClearHistoryAction:(id)sender
    {
    	UIActionSheet *actionSheet = [[UIActionSheet alloc]
    								  initWithTitle:@"Clear History?"
    								  delegate:self
    								  cancelButtonTitle:@"Cancel"
    								  destructiveButtonTitle:@"OK"
    								  otherButtonTitles:nil];
    
    	
    	// use the same style as the nav bar
    	actionSheet.actionSheetStyle = self.navigationController.navigationBar.barStyle;	
    	
    	[actionSheet showInView:self.view];
    [actionSheet release];
    
    
    }
    
    
    if select ok do this:

    Code:
    
    - (void)actionSheet:(UIActionSheet *)actionSheet
    
    didDismissWithButtonIndex:(NSInteger) buttonIndex
    {
    	if (!buttonIndex == [actionSheet cancelButtonIndex])
    	{
    		
    		//do what i want here!
    	}
    }
    
    at header file, UIActionSheetDelegate is included @ @interface.


    thks for your time. :)
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    This code works fine. Must be something else you're doing.
     
  3. macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #3
    It could be that the cancel button is obscured (in window Z-order) by a toolbar. This can be proven by attempting to click near-the-top of the cancel button -- if that works then you need to check UIActionSheet APIs that begin with "show"... Good luck :)
     
  4. thread starter macrumors member

    Joined:
    Jul 31, 2010
    #4
    hey thats the problem!!, now how do i solve this..
    solve!!! thks!!!
     
  5. macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #5
    Cool. Check UIActionSheet APIs that begin with "show"... :D
     
  6. macrumors newbie

    Joined:
    Nov 19, 2009

Share This Page