关于IOS xcode7 UITextField和UIButton 点击无反应是什么情况!

2025-04-07 00:31:32
推荐回答(1个)
回答1:

O(∩_∩)O哈哈哈~醉了我看的。。。

小伙子,VC的UI应该在xib,storyboard上实现,或者纯代码这,应该在VC.m的loadview方法里初始化UI,
其次,你的textfield不应该是加在window上,而是加在vc的view上。即:

@implememtation

-(void)loadView
{
[super loadView];

UITextField * textField=[[UITextField alloc]initWithFrame:CGRectMake(10, 40, 100, 50)];
textField.placeholder = @"hello,";

[self.view addSubview:textField];

}

然后,在你的上述代码中,删除以下代码:
UITextField * text=[[UITextField alloc]initWithFrame:CGRectMake(10, 40, 100, 50)];

text.backgroundColor=[UIColor blueColor];

text.textColor=[UIColor greenColor];

text.text=@"IOSIOSIOS";

text.textAlignment=NSTextAlignmentCenter;

text.keyboardType=UIKeyboardTypeNamePhonePad;

[self.window addSubview:text];