Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 10-09-2008, 01:51 PM   #8 (permalink)
giacomop81
New Member
 
Join Date: Jun 2008
Posts: 7
giacomop81 is an unknown quantity at this point
Default

Quote:
Originally Posted by myersn024 View Post
Alright, here's the goods. The first thing that you'll want to do is to alloc your UIAlertView and then initWithTitle:message:delegate:cancelButtonTitle: otherButtonTitles: just like normal. Then with all that good stuff done, you use the method addTextFieldWithValue:label:. The value is for initializing some text into the text field. The label is for setting a placeholder. Here's some example code.

Code:
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"Alert title" message:@"alert message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
[myAlert addTextFieldWithValue:nil label:@"<place holder>"];
[[myAlert textField] setTextAlignment:UITextAlignmentCenter];
[[myAlert textField] becomeFirstResponder];
[myAlert show];
[myAlert release];
myAlert = nil;
If you don't tell the text field to become first responder before showing the alert view, you'll wind up with two keyboards. That took a little messing with to get things straightened out. Then, to access the value that was entered into the text field when the ok button is clicked, you just do something like this. In this particular example, myString is an iVar that's already been alloc'ed and init'ed. Thus far, I've not figured out a way to make the text field return if the user presses the return button on the keyboard. I've tried all kinds of things and nothing that I've tried works.

Code:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
     switch(buttonIndex) {
         case 0:
              [myString setText:@"Cancel button pressed"];
              break;
         case 1:
              [myString setText:[[alertView textField] text]];
              break;
     }
}
Just so you know, this will compile and you will get some warnings saying that UIAlertView may not respond to the messages, but it will.
I found it very usefull, but now in need to get the string in the editField. How can i get it?
Thanks
giacomop81 is offline   Reply With Quote
 

» Advertisements
» Online Users: 355
13 members and 342 guests
AlanR917, AyClass, blakeart113, Domele, esoteric, ilmman, ipodphone, Kirkout, martianflash, Newbie123, Objective Zero, olivia325, Sesio
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,566
Threads: 94,081
Posts: 402,751
Top Poster: BrianSlick (7,990)
Welcome to our newest member, blakeart113
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:12 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.