输入未显示在UITextView中的文本。

时间:2022-09-10 20:33:45

I have an app i'm trying to port over to iOS 7. As there are no longer any textfields in iOS 7 UIAlertViews. (See here) I have to resort to using 2 UIViews managed by 1 ViewController. I didn't use nib files and just program the UI from code.

我有一个应用程序,我想把它移植到ios7上。在ios7 UIAlertViews中不再有任何文本字段。(参见这里)我必须使用由一个ViewController管理的两个uiview。我没有使用nib文件,只是从代码中编写UI。

When the app is started, the second UIView is stacked on top of the first one, it has a UITextField that takes in a user input. This code works in iOS 7 but does not work on iOS 6 devices.

当应用程序启动时,第二个UIView在第一个UIView之上,它有一个UITextField,它接收用户输入。该代码在ios7中工作,但在ios6设备上不起作用。

In an iOS 6 device, when I tap on the textfield in the 2nd UIView, the keyboard appears. However when I enter something into the textfield, no characters appear. I even tried to NSLog the characters entered by the keyboard and got NULL which means no text is entered!

在ios6设备中,当我在第二个UIView中点击textfield时,键盘会出现。但是,当我在textfield中输入一些东西时,没有出现字符。我甚至尝试了NSLog键盘输入的字符,并得到NULL,这意味着没有输入文本!

The code is as follows for the primary ViewController:

主视图控制器的代码如下:

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

Inside the View1.m:

在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];

Does any know what has changed in iOS 7 that 'allows' this behaviour? IS it a bug in iOS 7 or the SDK?

有人知道ios7中发生了什么改变了这种行为吗?它是ios7中的bug还是SDK?

1 个解决方案

#1


0  

The problem is in your code i did not see any text you are setting, you are just allocating for example refer below:-

问题是在你的代码中,我没有看到任何你正在设置的文本,你只是在分配如下的例子:-。

(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];
}

#1


0  

The problem is in your code i did not see any text you are setting, you are just allocating for example refer below:-

问题是在你的代码中,我没有看到任何你正在设置的文本,你只是在分配如下的例子:-。

(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];
}

相关文章