【问题标题】:Multiview: clear state of the second view when getting back to the first view in iOS SDKMultiview:在iOS SDK中返回第一个视图时清除第二个视图的状态
【发布时间】:2012-07-13 00:18:46
【问题描述】:

我正在编写一个有 2 个视图的程序。从主视图,即 FirstView,我通过以下方式移动到第二个视图:

-(IBAction)switchToSecondView:(id)sender{

    SecondViewController *screen=[[SecondViewController alloc] initWithNibName:nil bundle:nil];
    screen.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
    [self presentModalViewController:screen animated:YES];
    [screen release];
}

在第二个视图中,我有一个按钮和一个标签。 SecondView 是一个简单的活动,其 Label 的值从 0 开始。每次单击一个按钮都会导致 Label 增加 1。所以我对 SecondView 所做的是单击按钮将 Label 的新值设置为 5。

然后我通过调用返回到 FirstView:

[self dismissModalViewControllerAnimated:YES];

那么结束,我又回到了SecondView,但是Label的值还是5,这说明SecondView的状态不明确。

有没有办法在离开时清除所有 Second View 的状态?谢谢

【问题讨论】:

  • 您的第二个观点究竟是什么? UITextfields 等?
  • @nicktones:我刚刚在我的问题中添加了一些内容。

标签: ios sdk


【解决方案1】:

你说的文本视图是指 UILabel 吗?

如果是这样,那么这将实现您所追求的 -

    -(void)viewWillDisappear:(BOOL)animated
{
    nameOfUILabel.text = @"";
    [navController viewWillDisappear:animated];
}

这会将 UILabel 的文本值设置为空字符串

【讨论】:

  • 我刚改成标签,抱歉弄错了Android SDK。但是,如果我有许多其他州怎么办?我想一起重置
  • 只需在大括号之间添加行。与示例中的相同,但适用于您的其他对象
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多