可编辑文本字段的UITableView列表

时间:2022-04-06 19:36:16

I know it might not be according to Apple's human interface guidelines for the iPhone, but I want to get rid of one level of pushing views and have a list of editable text fields. Further, I want the keyboard to be on screen from start when the view appears.

我知道这可能不符合苹果的人机界面指南,但我想去掉一个层次的推送视图,并列出一个可编辑的文本字段列表。此外,当视图出现时,我希望键盘在屏幕上显示。

The problem is that when I have more than three such fields then the pop-up keyboard will cover the fields below. And the user can't scroll down to them. I think it's because the table view is full-screen. I've tried to make the list only as heigh as it would allow the keyboard to be visible all the time, but no luck.

问题是,当我有超过三个这样的字段时,弹出式键盘将覆盖下面的字段。用户不能向下滚动。我想这是因为表格视图是全屏的。我试着把这个列表做得尽可能的高,这样可以让键盘一直显示出来,但是运气不好。

Anyone knows how I should arrange things to get what I want?

谁知道我该怎么安排才能得到我想要的东西?

2 个解决方案

#1


2  

If you truly never need the keyboard to go away, The UITableView does not have a reason to be fullscreen. You can change the frame like this (where HEIGHT is the number of pixels the tableview will take up between its origin and the top of the keyboard):

如果你真的不需要键盘离开,UITableView就没有全屏的理由。您可以这样修改框架(其中高度是桌面视图在其起点和键盘顶部之间所占像素的数量):

tableView.frame = CGRectMake(0,0,320,HEIGHT);

tableView.frame = CGRectMake(0 0320高度);

#2


1  

If you insist on forcing the user to live with such a small input area the whole time, you can facilitate text input by having the return key also automatically jump to the next text input field by overriding the UITextEditDelegate method:

如果你坚持让用户一直使用这么小的输入区域,你可以通过返回键自动跳转到下一个文本输入字段,重写UITextEditDelegate方法:

- (BOOL)textFieldShouldReturn:(UITextField *)textField
    {
        if ( textField == self.firstNameField )
        {
            [self.lastNameField becomeFirstResponder];
        }
        else if ( textField == self.lastNameField )
        {
            [self.addressField becomeFirstResponder];
        }
        else if ( textField == self.addressField )
        {
            [self.cityField becomeFirstResponder];
        }
        else if ( textField == self.cityField )
        {
            [self.stateField becomeFirstResponder];
        }
        else if ( textField == self.stateField )
        {
            [self.zipcodeField becomeFirstResponder];
        }
        else if ( textField == self.zipcodeField )
        {
            [textField resignFirstResponder];

            [self.scrollView scrollRectToVisible:self.firstNameField.frame animated:YES];
        }


        return YES;
    }

This example will let the user input the fields for name & address in order without having to manually scroll the next text field into view and without the keyboard dismissing and reappearing.

这个示例将允许用户按顺序输入名称和地址字段,而不必手动将下一个文本字段滚动到视图中,也无需键盘取消和重新出现。

#1


2  

If you truly never need the keyboard to go away, The UITableView does not have a reason to be fullscreen. You can change the frame like this (where HEIGHT is the number of pixels the tableview will take up between its origin and the top of the keyboard):

如果你真的不需要键盘离开,UITableView就没有全屏的理由。您可以这样修改框架(其中高度是桌面视图在其起点和键盘顶部之间所占像素的数量):

tableView.frame = CGRectMake(0,0,320,HEIGHT);

tableView.frame = CGRectMake(0 0320高度);

#2


1  

If you insist on forcing the user to live with such a small input area the whole time, you can facilitate text input by having the return key also automatically jump to the next text input field by overriding the UITextEditDelegate method:

如果你坚持让用户一直使用这么小的输入区域,你可以通过返回键自动跳转到下一个文本输入字段,重写UITextEditDelegate方法:

- (BOOL)textFieldShouldReturn:(UITextField *)textField
    {
        if ( textField == self.firstNameField )
        {
            [self.lastNameField becomeFirstResponder];
        }
        else if ( textField == self.lastNameField )
        {
            [self.addressField becomeFirstResponder];
        }
        else if ( textField == self.addressField )
        {
            [self.cityField becomeFirstResponder];
        }
        else if ( textField == self.cityField )
        {
            [self.stateField becomeFirstResponder];
        }
        else if ( textField == self.stateField )
        {
            [self.zipcodeField becomeFirstResponder];
        }
        else if ( textField == self.zipcodeField )
        {
            [textField resignFirstResponder];

            [self.scrollView scrollRectToVisible:self.firstNameField.frame animated:YES];
        }


        return YES;
    }

This example will let the user input the fields for name & address in order without having to manually scroll the next text field into view and without the keyboard dismissing and reappearing.

这个示例将允许用户按顺序输入名称和地址字段,而不必手动将下一个文本字段滚动到视图中,也无需键盘取消和重新出现。