2012-07-10 38 views
0

我在UIAlertView中有一個UITableView,現在它顯示了一些非常醜陋的角落。我確實在willPresentAlertView()中放大了alertview的大小。UIAlertView奇怪的角落顯示

#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); 

     }   

    } 
} 

這可怎麼固定?謝謝! enter image description here

回答

1

看起來它剛剛伸展本身,而不是重繪其內容。你需要告訴它需要重繪([alertView setNeedsDisplay]),或將其內容模式重新繪製,使框架變化觸發重繪。

順便說一句,私有視圖層次的這個導航是非常脆弱的東西。它不會在iOS上花費太多時間來改變這個神祕的停止工作。

+0

我試了兩個[alertView setNeedsDisplay]和alertView.contentMode = UIViewContentModeRedraw,但我仍然得到了醜陋的角落。 – Yashu 2012-07-10 11:30:00

+0

你在哪裏把代碼?框架改變後? – jrturton 2012-07-10 12:13:57

+0

我把 「alertView.contentMode = UIViewContentModeRedraw;」之後: alertView.frame = CGRectMake(center,alertView.frame.origin.y,ALERT_VIEW_WIDTH,360); – Yashu 2012-07-10 12:25:32