The UIView inside the UIScrollView was not updated, despite the call to the "setNeedDisplay" method

I have UIScrollViewinside, some views are loaded from an xib file.

UIScrollViewonly loads three Views. Current, left and right.

For example, I have one view to the left and one view to the right of the current one View. If I scroll to the right, UIScrollViewdelete the view on the left, scroll right to the new current one Viewand load the new view to the right of the new current one View.

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

This works well, but sometimes, I don’t know why, when I click the button to change the background color in the view, it changes well, but the view does not refresh, so the user cannot see the background color change.

UIScrollView:

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

Method call when I press 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 the method setNeedsDisplayin the view loaded from xib, and the other view is inside the "border", but nothing works. In addition, my method is always called on the main thread.

Any suggestions?

Thanks!

Edit:

Obviously, I checked if the return view sliderGetViewWithID is the correct view. All attributes are well set. In my opinion, this is really an update problem.

+4
2

:

. UIScrollView UIScrollView. , !

[myView removeFromSuperView];
[myScrollView addSubview:myView];
0

, , , ? , , , .

, , scrollview myView. , , myView .

:

BOOL intersects = CGRectIntersectsRect(scrollview.bounds, myView.frame);
if(intersects == NO)
{
    NSLog(@"myView is offscreen");
}
0

All Articles