Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

newtoiphonesdk

macrumors 6502a
Original poster
Jul 30, 2010
567
2
Here is my setup:
I have a button that pulls an action sheet offering choices to save and email, save only, or print. If you press any of the options involving save, it pops up a uialertview with a textfield embedded, asking the user to type in a file name, and then a button for OK! and the cancelButton set to Dismiss. My problem right now is that in the UIAlertView, when you press the Dismiss button, it is behaving the same way as the otherButton. Any thoughts? Here is my code for these actions.
Code:
-(IBAction)action {
	
	UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:@"Share" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Save & Email", @"Save Only", @"Print", nil];
    [popup setTag:1];

	[popup showInView:self.view];
	[popup release];
	
}
- (void)actionSheet:(UIActionSheet *)popup clickedButtonAtIndex:(NSInteger)buttonIndex {
	if (popup.tag == 1) {
	switch (buttonIndex) {
		case 0:
		{
			
            [activity startAnimating];
            [self performSelector: @selector(savingforemail) 
                       withObject: nil 
                       afterDelay: 0];
            
		}
			
			break;
		case 1:
		{[activity startAnimating];
			[self performSelector: @selector(saving) 
					   withObject: nil 
					   afterDelay: 0];
			
			
		}
			
			break;
        case 2:
        {[activity startAnimating];
            [self performSelector:@selector(printer)
                       withObject:nil
                       afterDelay:0];
        }
            break;
			
	}	
	}
}
-(void)saving 
{UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Enter A File Name Here"     message:@"             " 
                                                delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:@"OK!", nil];
    alertTextField = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 260, 25)];

    
    
    [alertTextField setBackgroundColor:[UIColor whiteColor]];
    [alert addSubview:alertTextField];
    [alert setTag:1];
    [alert show];
    [alert release];
    [alertTextField release];  
    [activity stopAnimating];

}
-(void)savingforemail 
{UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"Enter A File Name Here"     message:@"                   " 
                                                delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:@"OK!", nil];
    alertTextField = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 260, 25)];
    
     
    [alertTextField setBackgroundColor:[UIColor whiteColor]];
    [alert2 addSubview:alertTextField];
    [alert2 setTag:2];
    [alert2 show];
    [alert2 release];
    [alertTextField release];  
    [activity stopAnimating];

}
- (void) alertView:(UIAlertView *) actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (actionSheet.tag == 1) {
  //my code to save only
    }
    if (actionSheet.tag == 2) {
        //my code to save and email
    }
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.