iPhone 中的重置按钮代码

发布于 2024-10-19 19:34:08 字数 132 浏览 1 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那片花海 2024-10-26 19:34:08

您不应在自己的代码中调用 -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.

我爱人 2024-10-26 19:34:08

resetToOriginalState 不是内置方法,您必须自己编写此方法,并且在单击相应按钮时调用此方法“resetToOriginalState:”,而不是调用 viewDidLoad 。如果您以编程方式创建按钮,您可以像这样设置该按钮的目标/操作:
resetBtn 是 UIButton 的实例:

UIButton *resetBtn = [[UIButton alloc] initWithFrame:CGRectMake(x,y,w,h)];

[resetBtn addTarget:self action:@selector(resetToOriginalState:) forControlEvents:UIControlEventTouchUpInside];

- (void)resetToOriginalState:(id)sender {
     //Do your stuff here 
}

如果您使用 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:

UIButton *resetBtn = [[UIButton alloc] initWithFrame:CGRectMake(x,y,w,h)];

[resetBtn addTarget:self action:@selector(resetToOriginalState:) forControlEvents:UIControlEventTouchUpInside];

- (void)resetToOriginalState:(id)sender {
     //Do your stuff here 
}

If your using Interface Builder connect the action method (resetToOriginalState) to the button.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文