【问题标题】:Clear and exit button清除和退出按钮
【发布时间】:2013-05-09 08:13:26
【问题描述】:

我有 2 个问题。

1) 如何在按下清除按钮时清除所有输入的文本字段和标签文本?

2) 按下退出按钮时如何退出应用程序?

谢谢

【问题讨论】:

    标签: ios xcode uibutton uitextfield exit


    【解决方案1】:
    1) How can I clear all entered textfields and label text when pressed clear button ?
    

    对于您的问题 1 从任何视图中删除所有子视图

    [self.view.subviews makeObjectsPerformSelector: @selector(removeFromSuperview)];
    

    如果您只想清除 UILabel 或 UITextField 中的文本

    -(IBAction)buttonPressed:(id)sender
    {
       yourFirstTxtField.text=@"";
       yourLabelField.text=@""
    }
    

    2) How can I exit from application when pressed exit button ?
    

    对于第二个使用How do I programmatically quit my iOS application?在 iPhone 应用程序开发中没有退出应用程序的概念。 应该导致应用退出的唯一操作是触摸手机上的 Home 按钮

    Apple 还提供Human Interface Guidelines show something like this.

    不要以编程方式退出

    但是有一些方法可以做到这一点,比如exit(0)

    还有[[NSThread mainThread] exit],我没试过。

    【讨论】:

      【解决方案2】:

      您可以将所有textfields and labels 枚举为:

       for (UIView *common in self.view.subviews) {
              if ([common isKindOfClass:[UITextField class]] || [common isKindOfClass:[UILabel class]]) {
                  commonTextField.text = @"";
              }
          }
      

      答案 2:现在可以退出您的应用程序。因为苹果不允许top强制退出应用。

      希望对你有所帮助。

      【讨论】:

      • 这将清除所有标签。甚至是您用来向用户指示某些信息的其他人。请务必处理好这种情况。
      【解决方案3】:
      -(void)fnClear{
      tf1.text = @"";
      ..
      lbl1.text = @"";
      ..
      }
      

      您无法在单击按钮时退出应用程序。 Apple 不推荐。

      【讨论】:

        【解决方案4】:

        对于第一个队列

        您可以为按钮单击创建一个 IBAction,然后在操作中将所有 Textfild 和 UILableVariable 设置为 nil 或 @"",如下例所示:-

        -(IBAction)Clear
        {
           txtFirstName.text=@"";
           lblFirst.text=@""
        }
        

        对于第二个队列

        Apple 没有提供任何你可以在你的项目中实现的方法,你必须按下 Home 按钮。

        【讨论】:

          猜你喜欢
          • 2011-11-30
          • 2017-06-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-08-26
          相关资源
          最近更新 更多