Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 不能';不在屏幕上显示文本字段_Iphone_Objective C_Uitextfield - Fatal编程技术网

Iphone 不能';不在屏幕上显示文本字段

Iphone 不能';不在屏幕上显示文本字段,iphone,objective-c,uitextfield,Iphone,Objective C,Uitextfield,我在viewDidLoad中添加了一个文本字段,但它并没有显示在屏幕上 这是 #import <UIKit/UIKit.h> @interface SecondViewController : UIViewController{ UITextField *tfText; } @property (nonatomic, retain) UITextField *tfText; @end 似乎您需要初始化对象。。。我是说 UITextField *newTextField =

我在viewDidLoad中添加了一个文本字段,但它并没有显示在屏幕上

这是

#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController{
    UITextField *tfText;
}
@property (nonatomic, retain) UITextField *tfText;
@end

似乎您需要初始化对象。。。我是说

UITextField *newTextField = [[UITextField alloc] init];
self.tfText = newTextField;
//....
//all your code here
//....
[newTextField release];

别忘了释放dealloc方法上的实例。

似乎需要初始化对象。。。我是说

UITextField *newTextField = [[UITextField alloc] init];
self.tfText = newTextField;
//....
//all your code here
//....
[newTextField release];

不要忘记在dealloc方法上释放实例。

D33pN16h7是正确的,您需要实例化您的对象。不过,我的做法与上面描述的稍有不同,没有理由创建UITextField实例,然后将实例设置为UITextField


self.tfText=[[UITextField alloc]init]

D33pN16h7是正确的,您需要实例化您的对象。不过,我的做法与上面描述的稍有不同,没有理由创建UITextField实例,然后将实例设置为UITextField

    UITextField entered2 = [[UITextField alloc] initWithFrame:CGRectMake(120.0, 125.0, 150.0, 25.0)]; 
[entered2 setBackgroundColor:[UIColor whiteColor]]; 
entered2.text=@"Active";    
[self.view addSubview:entered2];
[entered2 release];

self.tfText=[[UITextField alloc]init]

这是一个问题,因为它会生成内存泄漏,“alloc init”会在一个内存中增加保留计数,而属性setter(self.tfText)也会增加保留计数,所以我向您展示的代码是实例化对象的正确方法。干杯!这是一个问题,因为它会生成内存泄漏,“alloc init”“将保留计数增加一,属性设置器(self.tfText”)也会增加保留计数,因此我向您展示的代码是实例化对象的正确方法。干杯!
    UITextField entered2 = [[UITextField alloc] initWithFrame:CGRectMake(120.0, 125.0, 150.0, 25.0)]; 
[entered2 setBackgroundColor:[UIColor whiteColor]]; 
entered2.text=@"Active";    
[self.view addSubview:entered2];
[entered2 release];