Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redrawing a view in ios

Is it possible to redraw the whole view.

I need it to complete my language settings. The problem is that the language only changes after the views there drawn again. Like you go out of settings and then go in again, then the language is changed. But the moment you save everything, the language stays the same.

So how should i redraw my views, or by best the whole app, after the language change was found?

like image 510
Datenshi Avatar asked Oct 30 '12 08:10

Datenshi


People also ask

How do I force redraw a view in IOS?

Force a Redraw With setNeedsDisplaysetNeedsDisplay() forces a redraw of a particular view. Because you should never call draw(_ rect: CGRect) directly, you can think of setNeedsDisplay() as a method of asking UIKit for a redraw.

What is setNeedsDisplay?

setNeedsDisplay()Marks the receiver's entire bounds rectangle as needing to be redrawn.

What is update cycle in iOS?

The update cycle is the point at which control returns to the main run loop after the app finishes running all your event handling code. It's at this point that the system begins updating layout, display, and constraints.


2 Answers

In ARC:

- (void)setLanguage:(LanguageType)languageType
{
    _language = languageType;

    //TODO:your settings

    [_theWholeView setNeedsDisplay];
}

If that can not work , there is a very troublesome solution , it can reload the whole view.

You can code like this: In the view.h , you need creat a delegate. @protocol WholeViewDelegate

- (void)reloadData;

@end

In the view.m

- (void)setLanguage:(LanguageType)languageType
{
    _language = languageType;

    //TODO:your settings

    [_delegate reloadData];
}

In the controller you need to implement the delegate In the controller.m

- (void)reloadData
{
    if(_wholeView)
    {
        [_wholeView removeFromSuperview];
    }
    // in the wholeView init method you should refresh your data
    _wholeView = [[WholeView alloc] init];
    self.view addSubview:_wholeView
}
like image 75
cloosen Avatar answered Nov 15 '22 08:11

cloosen


Yes. Call [UIView setNeedsDisplay] (reference).

like image 44
trojanfoe Avatar answered Nov 15 '22 09:11

trojanfoe