我有UIAlertView
和UIAlertViewStyleSecureTextInput
風格。它工作完美。但是,當應用程序退出活動狀態,然後恢復活動狀態時,之前輸入到文本輸入中的文本仍然可見。但是當我試圖追加下一個字符時,所有以前的文本突然消失了。 什麼可能是這種行爲的原因,以及如何改變它?UIAlertView與UIAlertViewStyleSecureTextInput:收回活動後清除字段
回答
第一種方式
在ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
alert = [[UIAlertView alloc]init];
[alert setDelegate:self];
[alert setAlertViewStyle:UIAlertViewStyleSecureTextInput];
[alert show];
}
- (void)setText
{
UITextField *txt = [alert textFieldAtIndex:0];
[txt setText:@""];
}
在viewController.h
設置委託
#import "AppDelegate.h"
@interface ViewController : UIViewController <UIPopoverControllerDelegate,alerttext>
在appdelegate.h
@protocol alerttext <NSObject>
- (void)setText;
@end
#import <UIKit/UIKit.h>
@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
id <alerttext> delegate;
}
@property (strong, nonatomic) id <alerttext> delegate;
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@end
在appDelegate.m
@synthesize delegate;
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[self.viewController setText];
}
第二種方式
在viewcontroller.m
UITextField *text;
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
alert = [[UIAlertView alloc]init];
[alert setDelegate:self];
[alert setAlertViewStyle:UIAlertViewStyleSecureTextInput];
[alert show];
text = [alert textFieldAtIndex:0];
}
- (void)setText
{
[text setText:@""];
}
在ViewController.h ,只是聲明該方法
- (void)setText;
在appdelegate.m 只是把這個
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[self.viewController setText];
}
..... – 2013-04-04 13:27:45
這是默認行爲UIAlertViewStyleSecureTextInput
。
功能類似於UITextField
,其屬性secureTextEntry
設置爲YES
。
感謝您的回答。有沒有辦法改變這種行爲? – Thaven 2013-04-04 12:49:47
@Thaven:ASFAIK,沒辦法。或者您需要實施基於協議概念實現的自定義控件 – 2013-04-04 13:25:02
- 1. UIAlertView中:UIAlertViewStyleSecureTextInput:
- 2. UIAlertView,以UIAlertViewStyleSecureTextInput模式存在
- 3. 不活動的清除字段
- 4. 清除活動回棧android
- 5. 清除Postback後的字段
- 6. 如何區分UIAlertView取消和UIAlertViewStyleSecureTextInput的TextView返回?
- 7. 按下其他活動的按鈕清除回收站
- 8. 清除Android活動
- 9. 開始新活動後清除背景
- 10. 給Cleartop後活動堆棧未清除
- 11. 如何在還原到同一活動時清除EditText字段?
- 12. 根據回調清除輸入字段
- 13. 提交後清除所有字段
- 14. 如何在提交後清除字段?
- 15. 提交後清除Redux表單字段
- 16. 清除另一個文本輸入字段後清除
- 17. 清除JTextFields字段
- 18. 回發後清除隱藏的輸入字段
- 19. 如何在用戶正確回答後清除文本字段?
- 20. 如何在asp.net mvc中回發後清除字段?
- 21. 返回父活動與父活動中的錯誤清單
- 22. 活動後端堆棧上的回收活動視圖
- 23. 活動堆棧未清除
- 24. 清除活動堆棧android
- 25. Android內存清除活動
- 26. 清除一堆活動
- 27. 清除活動堆棧
- 28. UI自動清除帶有「清除按鈕」的文本字段
- 29. 從活動返回後保留片段
- 30. 從活動返回後更新片段
現在,當恢復活動的文本應該出現或根據你清楚嗎? – 2013-04-04 12:26:26
@Manohar重獲活躍文本時應該清楚。 – Thaven 2013-04-04 12:50:51
你的意思是應用程序丟失了什麼? – 2013-04-04 12:57:36