0

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

kokio
  • 53
  • 7
  • you can use with the help of tag – Ravindhiran Mar 14 '13 at 10:36
  • This may be of help to you: In iOS 5 there is a standardised `UIAlertView` complete with a textbox for basic input. Just set the style like so: `alert.alertViewStyle = UIAlertViewStylePlainTextInput;`. You can then extract what the user has entered like so: `- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSLog(@"Entered: %@",[[alertView textFieldAtIndex:0] text]); }` [Found here](http://stackoverflow.com/questions/6319417/whats-a-simple-way-to-get-a-text-input-popup-dialog-box-on-an-iphone). – Elliott Mar 14 '13 at 10:37

5 Answers5

4

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

}
Sean Lintern
  • 3,103
  • 22
  • 28
1

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];
}
Yashesh
  • 1,799
  • 1
  • 11
  • 29
1

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;       
}
Kumar
  • 7
  • 5
0

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;
}
Abhishek Singh
  • 6,068
  • 1
  • 23
  • 25
0

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]); 

}
Ravindhiran
  • 5,304
  • 9
  • 50
  • 82