简体   繁体   English

UIScrollView中的自定义UIView从未调用过drawRect

[英]Custom UIView in UIScrollView drawRect never called

I have in a controller: 我有一个控制器:

- (void)viewDidLoad {
   [super viewDidLoad];

   // Add a scroolView
   self.scroolViewDay.scrollEnabled = YES;
   // Compute the content Size of the TableDays
   self.scroolViewDay.contentSize = CGSizeMake(self.scroolViewDay.frame.size.width, 
                                               80 * 48); // TO MODIFY!
   [self.scroolViewDay addSubview:self.tableDays];
   [self.tableDays setNeedsDisplay];
}

The controller has a XIB where the UIScrollView is into. 该控制器具有XIB其中UIScrollView是成。 The custom view TableDays has a custom drawRect which is never called: 自定义视图TableDays有一个永远不会被调用的自定义drawRect

- (void)drawRect:(CGRect)rect {
    NSLog(@"sono in drawRect");
}

Why? 为什么?

-(void) setNeedsDisplay {
    [self.subviews makeObjectsPerformSelector:@selector(setNeedsDisplay)];
    [super setNeedsDisplay];
}

Add this code, and just override setNeedsDisplay method in your main view and I hope that you know that all of your subviews should be redrawn. 添加此代码,并在主视图中覆盖setNeedsDisplay方法,我希望您知道应重新绘制所有子视图。

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

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