Question

Using the following code to insert a subview in my UIView I get presented with a black screen. Can someone tell me why?

CJGBoardLabels* whiteLabels = [[CJGBoardLabels alloc] initWithFrame:self.frame 
    andOrientation:@"white" 
    andOrigin:self.boardOrigin 
    andSquareSize:_squareSize 
    andHorizontalOffset:_horizontalOffset 
    andVerticalOffset:_verticalOffset];

[self insertSubview:whiteLabels aboveSubview:self];

I get the same result with the following line too:

[self insertSubview:whiteLabels belowSubview:self];
Was it helpful?

Solution

Don't add subviews in the drawRect: method. Instead, use the actual triggering method to add the subviews, and preferably get the controller to add the subviews (not the view itself). So, call addSubview: in the controllers viewDidLoad or an action method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top