我對UITextField
有以下代碼。我遇到的問題是文本不會持續。例如,當我呈現模態視圖時,請將其解除,UITextField
不再包含文本。我希望文字留在那裏,直到我用文本字段減少視圖。在使用UITextField和NSString時遇到問題
我顯示UITextField
這樣的:
UITextField *nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
nameTextField.delegate = self;
[nameTextField addTarget:self action:@selector(editingEnded) forControlEvents:UIControlEventEditingDidEnd];
[nameTextField setEnabled: YES];
self.myTextField = nameTextField;
[nameTextField release];
然後,我有:
- (void)editingEnded
{
NSString *tempRoutineName = self.myTextField.text;
self.routineName = tempRoutineName;
[tempRoutineName release];
}
我發佈的第一塊代碼實際上是在configureCell方法中,因爲UITextField位於UITableViewCell中,所以我仍然應該在viewDidLoad中進行操作,或者在此方法中執行操作? – Jon
沒有。在'cellForRowAtIndexPath'方法中,初始化文本字段。 – Legolas
我不能'self.myTextField = textField',因爲'textField是在'configureCell'方法中聲明的。 – Jon