UIView inside an UIScrollView did not refresh itself despite call of method "setNeedDisplay"

Viewed 402

I've got an UIScrollView with inside, some views loaded from a xib file.

The UIScrollView loads only three Views. The current, the left one and the right one.

For exemple, I have one view at the left and one view at the right of the current View. If I scroll to the right, the UIScrollView will delete the view to the left, scroll to the right to the new current View and load the new view to the right of the new current View.

In addition, I have a button outside the UIScrollView. When I click on it, it changes the background color of the current view displayed on the UIScrollView.

It works well but sometimes, I don't know why, when I click on the button to change the background color of the view is well changed, but the view is not refresh so the user can't see the change of background color.

The UIScrollView:

container = [[UIScrollView alloc] initWithFrame:frame];
[container setBackgroundColor:[UIColor clearColor]];
[container setCanCancelContentTouches:NO];
[container setClipsToBounds:NO];
[container setShowsHorizontalScrollIndicator:NO];
[container setPagingEnabled:YES];

The method call when I click on the button to change the background color of the current view

- (void)menuColor:(MenuPickerViewController *)controller didPickOption:(UIView *)button
{
    // Get the object containing the data of the product linked with the view.
    MyProduct *product = (MyProduct *)[MyProduct getProduct:[_slider getCurrentContentDisplayed]];

    // Get the the superview of the button sender to have an access for the attributes of this button (color selected, ...)
    ColorButtonMenu *colorView = (ColorButtonMenu *)[button superview];

    // Get the current UIView displayed in the UIScrollView
    MyView *myView = (MyView *)[self sliderGetViewWithID:[_slider getCurrentContentDisplayed] FromSlider:_slider];

    // I check with debugger, the color is well setted
    product.color = colorView.color;

    // "border" is a view in my xib that I want change its background color.
    IFPrint(@"myView.border backgorund color before: %@\n", myView.border.backgroundColor.description);
    [myView.border setBackgroundColor:[Utilities colorFromHexString:colorView.color]];
    [myView.border setNeedsDisplay];
    IFPrint(@"myView.border backgorund color after: %@\n", myView.border.backgroundColor.description);

    IFPrint(@"=== DEBUG ===\n");
    IFPrint(@"isMainThread ? : %i\n", [NSThread isMainThread]); // Always return YES
    IFPrint(@"myView: %@\n", myView); // Always return the address of a valid pointer
    IFPrint(@"myView border: %@\n", myView.border); // Always return the address of a valid pointer
    IFPrint(@"=============\n\n");
}

So, as you can see at the end of the method, I tried to call method setNeedsDisplay on the view loaded from a xib and the other view inside "border" but nothings work. Moreover, my method is always called on the main thread.

Any suppositions ?

Thanks !

Edit:

Obviously, I have tested if the view return by sliderGetViewWithID is the correct view. All the attributes are well set. In my opinion it's truly a refresh problem.

2 Answers
Related