2013-05-09 86 views
0

我有2个问题。清除并退出按钮

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

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

感谢

回答

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

你的问题1中删除所有子视图形成任何意见

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

,如果你只希望清除文本INTI的UILabel或的UITextField

-(IBAction)buttonPressed:(id)sender 
{ 
    [email protected]""; 
    [email protected]"" 
} 

而且

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

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

而且苹果提供Human Interface Guidelines show something like this.

不要退出编程

但有一些办法做到这就像exit(0)

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

+1

谢谢你的回答 – Mhmt 2013-05-09 08:29:10

+0

祝你好运年轻人..! – Buntylm 2013-05-09 08:31:12

1

您可以通过所有textfields and labels列举如下:

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

答2:现在有办法退出应用程序。因为苹果不允许顶部从应用程序中退出。

希望它可以帮助你。

+0

这将清除所有标签。甚至你正在使用的其他人向用户指出一些信息。请确保你处理这种情况。 – Mohith 2013-05-09 08:21:01

+0

@Nishant Tyagi谢谢你的回答 – Mhmt 2013-05-09 08:28:17

1
-(void)fnClear{ 
tf1.text = @""; 
.. 
lbl1.text = @""; 
.. 
} 

您不能从按钮单击时退出应用程序。它不被Apple推荐。

+0

@Mohitth谢谢你的回答 – Mhmt 2013-05-09 08:27:44

1

对于首先阙

可以为按钮单击创建一个IBAction为有在行动,你把你所有的Textfild和UILableVariable作为零或@“”像波纹管示例: -

-(IBAction)Clear 
{ 
    [email protected]""; 
    [email protected]"" 
} 

对于二阙

有苹果不提供,你可以在你的项目中进行应用程序必须按Home键实现任何方法。