tags:

views:

1627

answers:

2

I am setting up an alert with a text field in it so players can enter their name for a high score. The game is oriented in landscape mode, but when I call to show the alert, the alert pops up in portrait mode while two keyboards are displayed, one in landscape and one(that's the size of the landscape one) in portrait mode. Here's the code I'm using to setup the alert dialog:

    UIAlertView* dialog = [[[UIAlertView alloc] init] retain];
[dialog setDelegate:self];
[dialog setTitle:@"Enter Name"];
[dialog setMessage:@" "];
[dialog addButtonWithTitle:@"Cancel"];
[dialog addButtonWithTitle:@"OK"];
[dialog addTextFieldWithValue:@"name" label:@""];
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 100.0);
[dialog setTransform: moveUp];
[dialog show];
[dialog release];

How do I make the alert show in landscape orientation and prevent it from showing two keyboards?

Thanks, Ben

+1  A: 

For those who may care, here's a working solution, which works properly in landscape mode:

UIAlertView* dialog = [[[UIAlertView alloc] init] retain];
[dialog setDelegate:self];
[dialog setTitle:@"Enter Name"];
[dialog setMessage:@" "];
[dialog addButtonWithTitle:@"Cancel"];
[dialog addButtonWithTitle:@"OK"];

nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[nameField setBackgroundColor:[UIColor whiteColor]];
[dialog addSubview:nameField];
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 100.0);
[dialog setTransform: moveUp];
[dialog show];
[dialog release];
[nameField release];

Make sure you've created UITextField * nameField; in your .h file, then you can get at the text the user typed in by doing: inputText = [nameField text];

in the - (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex method.

I see you do dialog=[[[UIAlertView alloc] init] retain] and [dialog release]. Both alloc and retain should be matched with one release, so I think there's a leak (unless there's another release somewhere else in your program); the 'retain' seems unnecessary in any case since alloc does it too.
squelart
So should I ditch the retain and release or what would be an appropriate solution? I think I'm missing something...
A: 

How did you stop tow keyboards appearing? I have 3 uitextfields in a uiView and when I go to a different view it just puts the new keyboard semi-transparently on top of the other..

Thanks, Dan

Dan Morgan
Dan - honestly, I don't know, I just kept messing around with the code until two stopped popping up...