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

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

问题描述

我在使用 setNeedsDisplay 时遇到问题.我有一个带有很多子 UIView 的 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,这里是层次结构:

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

  • UIView
    -- UIViewContainer
    --- UIView0
    --- UIView1
    --- UIViewStapel

我希望做什么:

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

我的detailview中有很多子视图(uiviews),见上面的层次结构.我在 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天全站免登陆