DefenestrationDay
DefenestrationDay

Reputation: 3830

UIAlertView not showing message text

I am bringing up an UIAlertView that works fine in portrait layout, but when in landscape mode - the message doesn't appear.

It is a standard UIAlertView, with three buttons.

UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"one", @"two", nil];

I have tried moving the buttons down (according to the height of the message label) and resizing the alert according to the relocated buttons, but the message still doesn't appear, despite there being plenty of room for display.
Setting the UILabel background to some color for debugging shows that it just isn't displayed..

EDIT:

The UILabel is there - It's just not being displayed.
In the willPresentAlertView method, I can see the UILabel in the NSAlertView's subviews.

Upvotes: 0

Views: 2316

Answers (3)

Mihai Timar
Mihai Timar

Reputation: 1160

It appears to be a bug with the layout code for UIAlertView. After fiddling a bit in the debugger I managed to get this workaround:

UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"one", @"two", nil];

[alert show];

// for some reason we have alpha 0 for 3 or 4 buttons
[[[alert subviews] objectAtIndex:2] setAlpha:1];
// also, for 3 buttons the height goes to 10 -> proof of concept 'fix'
[[[alert subviews] objectAtIndex:2] setFrame:CGRectMake(12, 45, 260, 24)];

[alert release];

This is just a proof of concept. A real workaroung should iterate ober the subviews and fix only labels that have either height to small or alpha==0

Upvotes: 2

Rajesh Maurya
Rajesh Maurya

Reputation: 3164

You can directly use uialertview and create object of it. Then pass title and message and button and also other button.....And call click button method.

//Example

UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Title" message:@"The message."
delegate:self cancelButtonTitle:@"button 1" otherButtonTitles:@"button", nil];
                  [alert show];
                  [alert relaese];


//Then use this method

-(void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
// the user clicked one of the ok/cancel buttons
    if(buttonIndex==0)
     {
       NSLog(@"Ok");
     }
     else
     {
     NSLog(@"cancel");
     }
}

Upvotes: -1

DAS
DAS

Reputation: 1941

Probably you missed:

[alert show];

Upvotes: 1

Related Questions