Redrawing a view in ios

前端 未结 3 1432
你的背包
你的背包 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
    }
    
    0 讨论(0)
  • 2021-01-19 04:16

    Yes. Call [UIView setNeedsDisplay] (reference).

    0 讨论(0)
  • 2021-01-19 04:17

    Just call setNeedsDisplay.. It will resolve the problem. setNeedsDisplay actually calls the drawRect function in the UIView class by passing the frame of the view as the rectangular parameter. Hope that helps....

    0 讨论(0)
提交回复
热议问题