【发布时间】:2013-08-02 18:08:05
【问题描述】:
假设我们有一个应用程序的登录屏幕。登录屏幕实现了一个UITableViewController,其中包含一个UITableView。 UITableView 有 1 个部分,该部分包含两个单元格(参见下面的故事板)。
当前行为
当用户开始编辑电子邮件字段时 - 使用占位符 ENTER YOUR EMAIL - 键盘与密码字段重叠 - 使用占位符 ENTER YOUR PASSWORD。
期望的行为:
当用户开始编辑电子邮件字段时,键盘应该与两个字段重叠,并且键盘应该位于两个字段下方。
尝试的解决方案
我试图在我的LoginFormController : UITableViewController 中使用以下内容来强制UITableView 滚动到适当的位置,但无济于事:
-(BOOL) textFieldSHouldBeginEditing:(RCTextField *)textField
{
[[self.view viewWithTag:textField.tag+1] becomeFirstResponder];
// get the scroll index path of the last row in the first section
NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:1 inSection:0];
// scroll the view there
[[self tableView] scrollToRowAtIndexPath:scrollIndexPath
atScrollPosition:UITableViewScrollPositionBottom animated:YES];
return YES;
}
我的LoginFormController : UITableViewController界面:
//
// LoginFormController.h
// Zealoushacker
//
// Created by Alex Notov on 7/31/13.
// Copyright (c) 2013 Zealoushacker, Inc. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface LoginFormController : UITableViewController <UITextFieldDelegate>
@end
LoginFormController 当然引用了tableView。
【问题讨论】:
-
以下解决方案中的任何一种方法都不能解决其余内容滚动与故障到位的问题。该线程中的解决方案似乎比以下答案中的任何解决方案都更优雅,但也不能按预期工作:stackoverflow.com/questions/16547549/…
标签: ios objective-c uitableview