如何点击一些按钮重新加载我的UIViewController? [英] How to reload my UIViewController on click of some buttons?

查看:337
本文介绍了如何点击一些按钮重新加载我的UIViewController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iPhone应用程序,我有一个 UIViewController 类,其中有一些coverflow动画,根据设计,我的视图顶部有5个按钮单击按钮时,按钮有一个 IBAction 方法我需要显示不同数据的封面流,并且封面流的计数也从1个按钮动作变为另一个。我的问题是如何在点击这些按钮时刷新我的页面(重新加载),因为我知道显式调用 viewDidLoad 是一个非常糟糕的主意,所以我该如何实现这一目标?任何帮助都提前感谢谢谢。

I'm developing an iPhone app, i have a UIViewController class where some coverflow animations are there and according to design i have some 5 buttons on top of my view each button have an IBAction method on clicking a button i need to display different set of coverflow with different data and the count of coverflow also changes from 1 button action to another. My problem is how can i refresh my page(reload) on click of these buttons, as i know calling explicitly viewDidLoad is a very bad idea, so how can i accomplish this? Any help is appreciated in advance thank you.

推荐答案

获取视图重新绘制自己的最简单方法是调用[ UIView setNeedsDisplay]或使用[UIView setNeedsDisplayInRect]。此方法告诉视图它需要重新绘制自己及其子视图。但是你不应该总是打电话给这个。还有其他方法可以导致视图重绘自己。例如,如果使用[UIView addSubview:]或[UIView removeFromSuperview]向视图层次结构添加或删除视图。

The easiest way to get a view to re-draw itself is to call [UIView setNeedsDisplay] or by using [UIView setNeedsDisplayInRect]. This method tells the view that it needs to re-draw itself and it's subviews. However you shouldn't always have to call this. There are other methods that can cause views to redraw themselves. For instance if you add or remove a view to the view hierarchy using [UIView addSubview:] or [UIView removeFromSuperview].

这些方法会导致系统调用视图的drawInRect :方法(假设您使用自定义绘图代码覆盖它)。如果您没有为自定义绘图覆盖此方法,则应该使您的子视图收到相同的消息,以便他们有机会重绘。

These methods cause the system to call your view's drawInRect: method (assuming you overrode it with custom drawing code). If you did not override this method for custom drawing then it should cause your subviews to receive the same message so that they can get a chance to redraw.

此处提供更多信息。具体请阅读标有查看绘图周期的部分。

Additional information here. Specifically read the section labeled "The View Drawing Cycle".

http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html

这篇关于如何点击一些按钮重新加载我的UIViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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