重新加载/刷新子视图 - setNeedsDisplay不起作用 [英] reload/refresh subViews - setNeedsDisplay doesnt work

查看:161
本文介绍了重新加载/刷新子视图 - setNeedsDisplay不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到setNeedsDisplay问题。我有一个带有很多子UIViews的UIView,在Inteface Builder中创建。我还有一个带有IBAction的按钮。在这个IBAction中我想重绘/重新加载所有UIViews(或所有UIElements,如UILabel,UIWebView等等)。

i have trouble with setNeedsDisplay. I have an UIView with a lot of sub UIViews, created in Inteface Builder. I have also an Button with IBAction. In this IBAction i want to redraw/reload all UIViews (or all UIElements, like UILabel, UIWebView and so on..)

我这样做,这不是为我工作,不知道原因..:

I am doing this, which doesn't work for me, dont know why.. :

//redraw the UIViews
[self.view_card_0 setNeedsDisplay];
[self.view_card_1 setNeedsDisplay];
[self.view_card_stapel setNeedsDisplay];

//other UI Elements
[self.webView_0 setNeedsDisplay];
[self.webView_1 setNeedsDisplay];
[self.webView_stapel setNeedsDisplay];

[self.lblCardTitle_0 setNeedsDisplay];
[self.lblCardTitle_1 setNeedsDisplay];
[self.lblCardTitle_stapel setNeedsDisplay]; 

[self.img_card_0 setNeedsDisplay];
[self.img_card_1 setNeedsDisplay];
[self.img_card_stapel setNeedsDisplay];

如何重绘/重新加载/刷新所有UIElements / UIViews和Subviews?

What to do for redraw/reload/refresh all UIElements/UIViews and Subviews?

编辑1:

我如何加载视图:

detailViewController = [[DetailViewController alloc]  
initWithNibName:@"DetailViewController_iPad" bundle:[NSBundle mainBundle]];  

detailviewcontroller没有viewcontroller,只是uiviews,这里是hierarchie:

The detailviewcontroller has no viewcontroller, just uiviews, here the hierarchie:


  • UIView

    - UIViewContainer

    --- UIView0

    --- UIView1

    --- UIViewStapel

我期望做什么:

* 我不想重置UIView,我想改变它们的背景和内容。 *

我在我的detailview中有很多子视图(uiviews),见上面的hierarchie。我在UIViews中显示内容,内容来自coreData。

view1包含coreData的当前行。

view0包含coreData的前一行。

viewStapel包含coreData的下一行。

I have in my detailview a lot of subviews (uiviews), see above hierarchie. I am displaying content in the UIViews, the content comes from coreData.
The view1 contains the current row of coreData.
The view0 contains the previous row of coreData.
The viewStapel contains the next row of coreData.

使用IBAction我想迭代coreData行,如果调用动作,则显示当前的下一行......依此类推..

With IBAction i want to iterate the coreData rows, display the next row in current if the action is called..and so on..

在Log中,数据已更改,但未在UIViews中显示。因此我需要重绘或重新加载或类似的东西,以显示当前数据。

In Log, the data is changed, but not displayed in the UIViews. Cause of this i need a redraw or reload or something like this, to get displayed the current data.

编辑2:已解决

我已将代码放入新方法并调用此方法解决了我的问题。

推荐答案

您是否尝试将视图和子视图重置为nib文件中的默认状态?

Are you trying to reset your view and subviews to their default state in the nib file?

如果是这样,上述方法将无效。自动执行此操作的唯一方法是从笔尖重新加载视图,但在我可以提供帮助之前,您需要更清楚地了解如何加载视图。

If so the approach above won't work. The only way to do that automatically is to re-load the views from the nib, but you'll need to be clearer about how you are loading the view in the first place before I can help.

如果要将其加载到视图控制器中,那么刷新它的最简单方法是从屏幕上删除视图控制器并重新创建它,但是您可以重新加载视图,说明这样的内容(来自控制器内):

If you are loading it into a view controller then the easiest way to refresh it is to remove the view controller from screen and re-create it, but you might be able to reload the view saying something like this (from within the controller):

UIView *parent = self.view.superview;
[self.view removeFromSuperview];
self.view = nil; // unloads the view
[parent addSubview:self.view]; //reloads the view from the nib

如果使用[[]直接从笔尖加载视图NSBundle mainBundle] loadNibNamed ...]或等效的,然后重新加载视图的最好方法就是抛弃它并再次调用该方法。

If you are loading the view directly from a nib using [[NSBundle mainBundle] loadNibNamed...] or equivalent, then best way to reload the view is just to throw it away and call that method again.

这篇关于重新加载/刷新子视图 - setNeedsDisplay不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆