簡體   English   中英

輸入的文本未顯示在UITextView中

[英]Entered text not showing in UITextView

我有一個應用程序正在嘗試移植到iOS7。因為iOS 7 UIAlertViews不再有任何文本字段。 (見這里 ),我不得不求助於使用2個UIViews 1個管理ViewController. 我沒有使用nib文件,而只是通過代碼對UI進行編程。

啟動應用程序時,第二個UIView堆疊在第一個UIView上,它具有一個UITextField可以接受用戶輸入。 此代碼在iOS 7中有效,但在iOS 6設備上無效。

在iOS 6設備中,當我點擊第二個UIView的文本字段時,將出現鍵盤。 但是,當我在文本字段中輸入內容時,沒有字符出現。 我什至嘗試對鍵盤輸入的字符進行NSLog並得到NULL ,這意味着沒有輸入任何文本!

主要ViewController的代碼如下:

//View1 : UIView
View1 *aView1;
[aView1 initWithFrame:CGRectMake(20,40,280,200) title:promptMsg]
[self.view addSubview:aView1];

在View1.m內部:

(id)initWithFrame:(CGRect) aRect title:(NSString*) promptStr{
self = [super initWithFrame:aRect];
UITextField *userField = [[UITextField alloc] initWithFrame:CGRectMake(x,y,a,b)];
[self addSubview:userField];

有誰知道iOS 7中“允許”這種行為的變化? 這是iOS 7還是SDK中的錯誤?

問題是在您的代碼中,我沒有看到您正在設置的任何文本,您只是在分配例如以下內容:

(id)initWithFrame:(CGRect) aRect title:(NSString*) promptStr{
self = [super initWithFrame:aRect];
UITextField *userField = [[UITextField alloc] initWithFrame:CGRectMake(x,y,a,b)];
userField.text=@"yourText"; // here setting the text
[self addSubview:userField];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM