简体   繁体   English

UIAlertView不显示消息文本

[英]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. 我正在创建一个在纵向布局中工作正常的UIAlertView,但在横向模式下 - 消息不会出现。

It is a standard UIAlertView, with three buttons. 它是标准的UIAlertView,带有三个按钮。

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.. 将UILabel背景设置为某种颜色以进行调试表明它只是不显示..

EDIT: 编辑:

The UILabel is there - It's just not being displayed. UILabel 在那里 - 它只是没有显示出来。
In the willPresentAlertView method, I can see the UILabel in the NSAlertView's subviews. willPresentAlertView方法中,我可以在NSAlertView的子视图中看到UILabel。

It appears to be a bug with the layout code for UIAlertView. 它似乎是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 一个真正的工作应该迭代子视图并仅修复高度为小或alpha == 0的标签

可能你错过了:

[alert show];

You can directly use uialertview and create object of it. 您可以直接使用uialertview并创建它的对象。 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");
     }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM