0

我在 UIAlertView 中有一个 UITableView,现在它显示了一些非常丑陋的角落。我确实在 willPresentAlertView() 中放大了警报视图的大小。

#define ALERT_VIEW_WIDTH 750
#define ALERT_PADDING 20
- (void)willPresentAlertView:(UIAlertView *)alertView {
    {
        NSLog(@"%@", [[alertView class] description]);

        id thing;
        if ( [[[alertView class] description] isEqualToString:@"UIAlertTableView"]){ //change the alert view size
            NSLog(@"center: %f", alertView.center.x);

            int center=alertView.center.x-ALERT_VIEW_WIDTH/2;
            for (thing in alertView.subviews)
            {
                NSLog(@"%@", [[thing class] description]);
                if([[[thing class] description] isEqualToString:@"UITableView"])
                {
                    UIView* v=(UIView*)thing;
                    v.frame=CGRectMake(v.frame.origin.x+ALERT_PADDING, v.frame.origin.y, ALERT_VIEW_WIDTH-ALERT_PADDING*3, 250);
                }
                if([[[thing class] description] isEqualToString:@"UIAlertButton"])
                {
                    //UIView* v=(UIView*)thing;
                    //v.frame=CGRectMake(v.center.x, v.frame.origin.y, 100, v.frame.size.height-10);
                }
                if([[[thing class] description] isEqualToString:@"UILabel"])
                {
                    //UIView* v=(UIView*)thing;
                    //v.frame=CGRectMake(center-v.frame.size.width/2, v.frame.origin.y, v.frame.size.width, v.frame.size.height);
                }
            }
            alertView.frame=CGRectMake(center, alertView.frame.origin.y, ALERT_VIEW_WIDTH, 360);

        }        

    }
}

如何解决这个问题?谢谢! 在此处输入图像描述

4

1 回答 1

1

It looks like it has just stretched itself, rather than redrawn its contents. You would need to tell it it needs redrawing ([alertView setNeedsDisplay]), or set its content mode to redraw, so that the frame change triggers a redraw.

As an aside, this navigation of private view hierarchies is pretty fragile stuff. It wouldn't take much of a change in iOS for this to mysteriously stop working.

于 2012-07-10T11:11:51.170 回答