UIAlertView not showing message text

前端 未结 3 644
情歌与酒
情歌与酒 2021-01-17 05:26

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 thre

相关标签:
3条回答
  • 2021-01-17 06:06

    Probably you missed:

    [alert show];
    
    0 讨论(0)
  • 2021-01-17 06:09

    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");
         }
    }
    
    0 讨论(0)
  • 2021-01-17 06:33

    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

    0 讨论(0)
提交回复
热议问题