iPad 清除所有字段返回开始

发布于 2024-10-11 10:43:14 字数 246 浏览 2 评论 0原文

我正在创建一个内部 iPad 应用程序,我们的员工可以在其中填写他们刚刚进行的现场访问的详细信息。

应用程序中的一个页面是一个巨大的表单,用户可以在其中输入所有信息。我在这个表格上有一个重置按钮。此按钮将仅清除所有文本字段、文本视图、取消选中复选框等。

是否有一种干净的方法将视图重置为状态,就好像它是全新的(不脏)一样。我真的不想检查视图上的每个控件并将其设置回空。

有没有办法擦除整个视图并重新启动?

提前致谢

Im creating an internal ipad app for which will allow our employees to fill in details on a site visit they have just performed.

One of the pages in the app is a massive form where the user enters all the information. I have a reset button on this form. This button will just clear all textfields, textviews, uncheck checkboxes etc etc.

Is there a clean way to reset a view to the state as if it is brand new (not-dirty). I dont really want to go through every control on the view and set it back to nothing.

Is there a way to wipe the entire view and restart again?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

风透绣罗衣 2024-10-18 10:43:14

我认为做到这一点的简单方法是,

-(IBAction) reset
{
      YourView *obj=[[YourView alloc] initWithNibName:@"YourView" bundle:[NSBundle mainBundle]];
      [self presentModalViewController:obj animated:NO];
      [obj release];
}

I think the easy-way to do this is by,

-(IBAction) reset
{
      YourView *obj=[[YourView alloc] initWithNibName:@"YourView" bundle:[NSBundle mainBundle]];
      [self presentModalViewController:obj animated:NO];
      [obj release];
}
心安伴我暖 2024-10-18 10:43:14

我认为最简单的方法是放弃您的视图(或您想要重置的部分)并重新创建它们。这可能很简单:

//assuming you have a nib file containing some custom FormView class with your current view controller as its owner and the FormView instance in the nib bound to a 'formView' property on the controller
[self.formView removeFromSuperView];
[[NSBundle mainBundle] loadNibNamed:@"FormView" owner:self options:nil];
[self.view addSubView:self.formView];
//keep a reference to the old formView first and animate the transition as you like

更复杂但可能值得的可能是让您的视图对象使用 KVO 来监视通过委托或超级视图作为属性公开的某些模型对象的更改。如果您希望视图能够自动更新自身以响应来自视图其他部分或某些外部源(例如网络更新)的模型更改,这会很方便。然后,“重置”就像用模型的新实例替换视图正在观察的属性值一样简单。

I think the easiest way to do this is to discard your view (or the sections of it you want to reset) and recreate them. That might be as simple as:

//assuming you have a nib file containing some custom FormView class with your current view controller as its owner and the FormView instance in the nib bound to a 'formView' property on the controller
[self.formView removeFromSuperView];
[[NSBundle mainBundle] loadNibNamed:@"FormView" owner:self options:nil];
[self.view addSubView:self.formView];
//keep a reference to the old formView first and animate the transition as you like

More complex but possibly worthwhile could be to have your view objects use KVO to watch for changes to some model object exposed as a property through a delegate or on a superview. That's handy if you want the view to be able to automatically update itself in response to changes to the model coming from other parts of the view or some external source like network updates. A "reset" could then be as simple as replacing that value of the property the views are observing with a new instance of your model.

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