iPhone 中的重置按钮代码
我的 iPhone 应用程序中有一个名为 Reset
的按钮。它用于重置目的。我为此调用了 viewDidLoad() 方法。对吗?
如何重置 iPhone 中的页面? 如何为此编写代码?任何帮助将不胜感激。
I have a button called Reset
in my iPhone application. It is for resetting purposes. I called viewDidLoad()
method for this. Is it right?
How to reset a page in iPhone?
how to write code for this? Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不应在自己的代码中调用
-viewDidLoad
。当视图刚刚完成加载时,它会在视图控制器(VC)上被调用。将 VC 返回到其原始状态很大程度上取决于情况的具体情况,但您可能可以将其属性等设置回其原始值,或者您可以分配并初始化一个新的 VC,从视图中删除旧 VC 的视图层次结构并添加新的 VC 视图。
或者,您可以在 VC 上实现
-resetToOriginalState
方法。You should not call
-viewDidLoad
in your own code. It gets called on view controllers (VCs) when their view has just finished loading.To return a VC to its original state depends largely on the specifics of the situation, but you could probably either set its properties and whatnot back to their original values or you could alloc and init a new VC, remove the old VC's view from the view hierarchy and add the new VC's view.
Alternately, you could just implement a
-resetToOriginalState
method on your VC.resetToOriginalState 不是内置方法,您必须自己编写此方法,并且在单击相应按钮时调用此方法“resetToOriginalState:”,而不是调用 viewDidLoad 。如果您以编程方式创建按钮,您可以像这样设置该按钮的目标/操作:
resetBtn 是 UIButton 的实例:
如果您使用 Interface Builder,则将操作方法 (resetToOriginalState) 连接到按钮。
resetToOriginalState is not a inbuilt method, you have to write this method on your own and instead of calling viewDidLoad call this method 'resetToOriginalState:' when the respective button is clicked. If you are creating button programmatically you can set the target/action of that button like this:
resetBtn is the instance of the UIButton:
If your using Interface Builder connect the action method (resetToOriginalState) to the button.