UIAlertView未显示消息文本



我提出了一个UIAlertView,它在纵向布局中运行良好,但在横向模式下不会显示消息。

它是一个标准的UIAlertView,有三个按钮。

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

我试着向下移动按钮(根据消息标签的高度),并根据重新定位的按钮调整警报大小,但消息仍然没有出现,尽管有足够的显示空间
将UILabel背景设置为某种颜色以进行调试表明它不会显示。。

编辑:

UILabel就在那里——它只是没有被显示
willPresentAlertView方法中,我可以在NSAlertView的子视图中看到UILabel。

这似乎是UIAlertView布局代码的一个错误。在调试程序中做了一些改动后,我设法找到了这个解决方法:

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];

这只是一个概念的证明。一个真正的工作组应该在子视图中迭代,只修复高度为small或alpha==0的标签。

可能您错过了:

[alert show];

您可以直接使用uialertview并创建它的对象。然后传递标题、消息和按钮以及其他按钮。。。。。并调用click-button方法。

//示例

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");
     }
}

最新更新