【发布时间】:2012-08-08 17:49:54
【问题描述】:
在我的登录视图中,我在包含两个单元格的分组表视图中有电子邮件和密码文本字段。我以编程方式添加了两个文本字段:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
_cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
_cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Cell"];
_cell.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
if (indexPath.row == 0) {
_emailTxtFld = [[UITextField alloc]initWithFrame:CGRectMake(10, 7, 277, 34)];
_emailTxtFld.placeholder = @"E-mail";
_emailTxtFld.font = [UIFont fontWithName:@"Helvetica-Bold" size:15];
_emailTxtFld.clearsOnBeginEditing = YES;
[_emailTxtFld setDelegate:self];
[_emailTxtFld setKeyboardType:UIKeyboardTypeEmailAddress];
[_cell.contentView addSubview:_emailTxtFld];
}
if (indexPath.row == 1) {
_passwordTxtFld = [[UITextField alloc]initWithFrame:CGRectMake(10, 7, 277, 34)];
_passwordTxtFld.placeholder = @"Password";
_passwordTxtFld.font = [UIFont fontWithName:@"Helvetica-Bold" size:15];
_passwordTxtFld.secureTextEntry = YES;
[_passwordTxtFld setDelegate:self];
_passwordTxtFld.clearsOnBeginEditing = YES;
[_cell.contentView addSubview:_passwordTxtFld];
}
return _cell;
}
这一切都在滚动视图上。触摸文本字段时,键盘会出现,并且滚动视图会出现,其余的视图可以通过滚动查看。问题是文本字段和表格视图以及我键入的文本消失了,当我触摸它们内部进行编辑时。我仍然可以看到自动更正,并且在我输入某些内容并且键盘返回后,一切都恢复正常,我可以看到我输入的文本。
如果我在keyboardDidShow 方法中注释掉所有内容,那么表格视图和文本字段不会消失。但显然我想保留这条线。
-(void)keyboardDidShow:(NSNotification *)notif
{
_logScrollView.frame = CGRectMake(0, 0, 320, 245);// This line commented out stops the problem
}
-(void)keyboardDidHide:(NSNotification *)notif
{
_logScrollView.frame = CGRectMake(0, 0, 320, 460);
}
如果我需要给你更多代码,请告诉我。 感谢您的回答!
【问题讨论】:
-
声望超过十个我就加图
-
它可能正在滚动到视野之外。您可以向上或向下滚动并“找到”文本字段吗?
-
是的,我认为你是对的。我无法在任何地方看到文本字段。我在下面的回答解决了这个问题。
标签: iphone ios uiscrollview uitextfield