2013-05-09 101 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鍵實現任何方法。