- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)] autorelease];
}
-(IBAction) add :(id)sender {
}
在视图文本字段中找不到的诀窍是当我单击添加textfiled时出现在视图中
答案 0 :(得分:0)
您可以提前创建文本字段并将其添加到视图中并将隐藏属性设置为YES,此外,您只需将hidden设置为NO即可使其显示。
- (void)loadView
{
UIView * newView = [[UIView alloc] init];
// retaining property
self.myTextField = [[[UITextField alloc] init] autorelease];
myTextField.hidden = YES;
[newView addSubview:myTextField];
self.view = newView;
[newView release];
}
- (IBAction)add:(id)sender
{
myTextField.hidden = NO;
}
每次调用add时都添加一个新的UITextField
- (IBAction)add:(id)sender
{
UITextField * textfieldToAdd = [[[UITextField alloc] init] autorelease];
// ... configuration code for textfield ...
[self.view addSubview:textfieldToAdd];
}