ios - 清除和退出按钮

标签 ios xcode uibutton uitextfield exit

我有 2 个问题。

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

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

谢谢

最佳答案

1) How can I clear all entered textfields and label text when pressed clear button ?

对于您的问题 1 从任何 View 中删除所有 subview

[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 应用程序开发中没有退出应用程序的概念。 唯一应该导致应用程序退出的操作是触摸手机上的主页按钮

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

不要以编程方式退出

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

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

关于ios - 清除和退出按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16457330/

相关文章:

ios - 将图像置于按钮中会产生意想不到的结果

swift - 准备(对于 : sender:) not getting called during segue from button to tab bar controller (in Swift 4, Xcode 9)

iphone - 保持 iPhone UIButton 突出显示

iphone - 将 NSNumber 转换为 BOOL Objective-C

ios - WKNavigationDelegate 应用程序在分配时崩溃

ios - LayerView AutoLayout 上的约束按钮

ios - 在iCloud仪表板中添加团队成员

ios - Xcode 无法删除 UIBarbuttonItem 而不会出现错误

ios - Xcode:应用程序图标始终位于项目根目录中

ios - 我们可以有多个动态链接指向单个应用程序吗?