Reputation: 939
I added a text field in viewDidLoad but it did not show up on screen.
Here's .h
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController{
UITextField *tfText;
}
@property (nonatomic, retain) UITextField *tfText;
@end
Here's .m
- (void)viewDidLoad{
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor lightGrayColor]];
tfText.frame = CGRectMake(65, 100, 200, 50);
tfText.backgroundColor = [UIColor whiteColor];
[tfText setTextColor:[UIColor blackColor]];
tfText.placeholder = @"Test";
[tfText setBorderStyle:UITextBorderStyleNone];
[self.view addSubview:tfText];
}
Upvotes: 0
Views: 65
Reputation: 139
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];
Upvotes: 0
Reputation: 354
D33pN16h7 is correct, you need to instantiate your object. However I would do it a little differently than described above, there is no reason to create a UITextField instance, and then set your instance to it.
self.tfText = [[UITextField alloc] init];
Upvotes: 0
Reputation: 2030
seems that you need to initialize the object... I mean
UITextField *newTextField = [[UITextField alloc] init];
self.tfText = newTextField;
//....
//all your code here
//....
[newTextField release];
And dont forget to release your instance on dealloc method.
Upvotes: 3