2013-04-04 14 views
0

我有UIAlertViewUIAlertViewStyleSecureTextInput風格。它工作完美。但是,當應用程序退出活動狀態,然後恢復活動狀態時,之前輸入到文本輸入中的文本仍然可見。但是當我試圖追加下一個字符時,所有以前的文本突然消失了。 什麼可能是這種行爲的原因,以及如何改變它?UIAlertView與UIAlertViewStyleSecureTextInput:收回活動後清除字段

+0

現在,當恢復活動的文本應該出現或根據你清楚嗎? – 2013-04-04 12:26:26

+0

@Manohar重獲活躍文本時應該清楚。 – Thaven 2013-04-04 12:50:51

+0

你的意思是應用程序丟失了什麼? – 2013-04-04 12:57:36

回答

0

第一種方式

在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]; 
} 
+0

..... – 2013-04-04 13:27:45

1

這是默認行爲UIAlertViewStyleSecureTextInput

功能類似於UITextField,其屬性secureTextEntry設置爲YES

+0

感謝您的回答。有沒有辦法改變這種行爲? – Thaven 2013-04-04 12:49:47

+0

@Thaven:ASFAIK,沒辦法。或者您需要實施基於協議概念實現的自定義控件 – 2013-04-04 13:25:02