应用程序因iOS sdk中的警报视图和操作表而挂起

时间:2013-07-22 12:42:13

标签: iphone ios uialertview uiactionsheet

我有一个textView&在TextViewDidEndEditing上,我显示一个带有两个按钮保存的警报?是的。

我还有图像按钮,当我点击resignFirstResponder进行textview时,会显示警告&还会显示操作表。

但是,操作表按钮不可点击&应用程序挂了。什么都没发生......

我的代码如下:

-(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];
}

2 个答案:

答案 0 :(得分:0)

ResignFirstResponder触发textViewDidiEndEditing。所以基本上你同时展示了UIAlertVIew和ActionSheet,我想这就是问题所在。

请定义您的用户界面流程,并尝试将这两个用户分开。

答案 1 :(得分:0)

听说我编写了实现此跳跃的代码,这有助于


  #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