I have a textView & on TextViewDidEndEditing
, i show a alert with two buttons save? Yes No.
I have also the image Button, when it is clicked i resignFirstResponder
for textview, so the alert will be shown & also shows the action sheet.
But the action sheet buttons are not clickable & app got hang. Nothing is happen....
My code is as follows:
-(void)textViewDidEndEditing:(UITextView *)textView
{
UIAlertView *alt=[[UIAlertView alloc]initWithTitle:@"" message:@"Do you want to save this note?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alt setTag:1];
[alt show];
}
-(IBAction)image_button:(id)sender
{
[MYTextView resignFirstResponder];
UIActionSheet *ac=[[UIActionSheet alloc]initWithTitle:@"Select the Option" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Photo Library",@"Camera Capture", nil];
ac.tag=4;
ac.delegate = self;
ac.backgroundColor=[UIColor blackColor];
[ac showInView:self.view];
}
ResignFirstResponder triggers textViewDidiEndEditing. So basically you are showing the UIAlertVIew and the ActionSheet at the same time, I guess that is the problem.
Please define your UI flow and try to seperate these 2.
hear i wrote code for implementing this hops this helps
#import "ViewController.h"
@interface ViewController ()<UITextViewDelegate,UIAlertViewDelegate,UIActionSheetDelegate>
@end
@implementation ViewController
@synthesize aTextView;
@synthesize aButton;
- (void)viewDidLoad
{
[super viewDidLoad];
self.aTextView.delegate = self;
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[self.aTextView release];
[self.aButton release];
[super dealloc];
}
-(void)textViewDidEndEditing:(UITextView *)textView
{
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == alertView.cancelButtonIndex)
{
NSLog(@"cancel");
}
else
{
NSLog(@"save hear");
UIActionSheet *aActionSheet = [[UIActionSheet alloc]initWithTitle:@"option" delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:nil otherButtonTitles:@"photo lib",@"camara lib", nil];
[aActionSheet showInView:self.view];
[aActionSheet release];
}
}
- (IBAction)whenButtonTapped:(id)sender {
[self.aTextView resignFirstResponder];
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"save" message:@"" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES",nil];
[alertView show];
[alertView release];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == actionSheet.cancelButtonIndex)
{
NSLog(@"cancel");
}
else if (buttonIndex == 0)
{
NSLog(@"save to photo lib");
}
else
{
NSLog(@"camara lib");
}
}
@end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.