How to show textField text in UIAlertView
I have a textField and a button. On the button I defined an alertview now I want what I write in textfield appear in alertview.
- (IBAction) btnClicked {
NSString *str=textTag.text;
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"Hello World!" message: str delegate: nil cancelButtonTitle:@"OK" otherButtonTitles: nil, nil];
[alert show];
[开发者_Python百科alert release];
}
The program is build successful but when I clicked on button nothing is displayed in the alertView.
What is the reason nothing is displayed?
What is textTag defined as? You need something such as this in your header file:
IBOutlet UITextField *textTag;
Not only that, you need to hook up textTag in interface builder to the actual text field. Have you done that?
To help diagnose the problem, add the following line below the NSString *str = ... line:
NSLog(@" Text I found in the text field = .%@.", textTag.text);
You should see your text field text appear in XCode console when you hit the button.
精彩评论