开发者

How to show textField text in UIAlertView

开发者 https://www.devze.com 2023-02-12 03:33 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消