Question

i can't get the value of textView from my alertView

UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(12, 50, 260, 100)];

    [textView setText:@""];

    UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"put text\n\n\n\n\n\n" message:@"" delegate:self cancelButtonTitle:@"Annuler" otherButtonTitles:@"Envoyer",nil];
    av.alertViewStyle = UIAlertViewStyleDefault;
    [av addSubview:textView];
    [av show]; 

it display alertview view with textview inside and its fine, i want to get the value of textview i my

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {        
}

can you help me please

Était-ce utile?

La solution

Declare textView for use throughout your class

@implementation objectTables
{
    UITextView *textView;
}

then in your

textView = [[UITextView alloc]initWithFrame:CGRectMake(12, 50, 260, 100)];

    [textView setText:@""];

    UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"Push Notification\n\n\n\n\n\n" message:@"" delegate:self cancelButtonTitle:@"Annuler" otherButtonTitles:@"Envoyer",nil];
    av.alertViewStyle = UIAlertViewStyleDefault;
    [av addSubview:textView];
    [av show]; 

and

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {     

   NSString *textViewText = [textView text];

}

Autres conseils

you can use - (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex which will return object of UITextField.

and from UITextField get text from it.

Or another way is

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{


UITextField *TextField = (UITextField *)[alertView viewWithTag:YOURTAG];
}

You can try this :

UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(12, 50, 260, 100)];
[textView setText:@""];
textView.tag = 10;
UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"put text\n\n\n\n\n\n" message:@"" delegate:self cancelButtonTitle:@"Annuler" otherButtonTitles:@"Envoyer",nil];
av.alertViewStyle = UIAlertViewStyleDefault;
[av addSubview:textView];
[av show]; 

In Delegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
      UITextView *textView = (UITextView *) [alertView viewWithTag:10];
      NSString *yourText = textView.text;       
}

Just Declare Your UITextView in .h File

UITextView *textView;

and in .m file

textView = [[UITextView alloc]initWithFrame:CGRectMake(12, 50, 260, 100)];

    [textView setText:@""];

    UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"put text\n\n\n\n\n\n" message:@"" delegate:self cancelButtonTitle:@"Annuler" otherButtonTitles:@"Envoyer",nil];
    av.alertViewStyle = UIAlertViewStyleDefault;
    [av addSubview:textView];
    [av show];

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{
//Gives you the Value of UITextView
        NSLog(@"%@",[textView text]); 
}

Or you can define it as the property in Extended class(.m file) and access it.

@Interface yourINterfaceName()
{
@property(nonatomic , retain ) UITextView *textView;
}

Try this

UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(12, 50, 260, 100)];

[textView setText:@""];
textView.tag =10;
UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"put text\n\n\n\n\n\n" message:@"" delegate:self cancelButtonTitle:@"Annuler" otherButtonTitles:@"Envoyer",nil];
av.alertViewStyle = UIAlertViewStyleDefault;
[av addSubview:textView];
[av show];



- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{

 UITextView *textView = (UITextView *)[alertView viewWithTag:10];
  NSLog(@"%@",[textView text]); 

}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top