2013-03-14 56 views
0

我無法從我的alertView得到的TextView的價值如何從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]; 

它顯示與TextView的內部和其優良的alertview觀點得到TextView的價值,我想要得到的TextView i的值我

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

你能幫助我請

+0

你可以用標籤 – Ravindhiran 2013-03-14 10:36:07

+0

的幫助下,這可能是幫助使用給你:在iOS 5中有一個標準的'UIAlertView'完成帶有用於基本輸入的文本框。只需像這樣設置樣式:'alert.alertViewStyle = UIAlertViewStylePlainTextInput;'。您可以提取用戶輸入的內容:' - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex NSLog(@「Entered:%@」,[[alertView textFieldAtIndex:0] text ]); }'[這裏找到](http://stackoverflow.com/questions/6319417/whats-a-simple-way-to-get-a-text-input-popup-dialog-box-on-an-iphone) 。 – 2013-03-14 10:37:56

回答

4

申報的TextView您

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

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

    NSString *textViewText = [textView text]; 

} 
1

你可以使用- (*的UITextField)textFieldAtIndex:(NSInteger的)textFieldIndex將回復O對象UITextField

UITextField從中獲取文本。

或者另一種方式是在你的類

@implementation objectTables 
{ 
    UITextView *textView; 
} 

然後使用

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


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

只需要聲明的.h文件中

UITextView *textView; 

和.m文件

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

或者你可以將其定義爲Extended class(.m文件)的屬性和訪問您UITextView

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

試試這個

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

} 
1

你可以試試這個:

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]; 
     NSString *yourText = textView.text;  
}