Redrawing a view in ios

前端 未结 3 1545
你的背包
你的背包 2021-01-19 03:46

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

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-19 04:11

    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
    }
    

提交回复
热议问题