how to move to next cell/row in table view with textview

大憨熊 提交于 2019-12-11 08:14:37

问题


i am stuck at this .please help me in sorting out this issue. this is my image now i have 5 different rows in the table. if u click on first textfield after editing the first field then i want done button click to goto the second field and open textview and textfield simulatneously(as shown in the image). The Category Filed is having picker view,The Name field (shown in image),Location is having same as image,price is having a action sheet.

Now i have added code for action sheet of Price Field .Can somebody help me achieve the required.Thanks for help... :)

i am doing something like this but it is not yet worked for me. the code is:

- (void) textFieldDoneTouched
{

    [self.site setValue:textField.text forIndex:selectedRow];

    [UIView animateWithDuration:0.3
                     animations:^{
                         CGRect f = textFieldContainerView.frame;
                         f.origin.y = self.view.frame.size.height;
                         textFieldContainerView.frame = f;
                     }];

    [textField resignFirstResponder];
    NSIndexPath *indexPath = [NSIndexPath indexPathForItem:selectedRow inSection:0];
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    self.tableView.userInteractionEnabled = YES;

    [self.view endEditing:TRUE];

    [self validateSiteData];
}

- (BOOL) textFieldShouldReturn:(UITextField *)textField
{

        [self textFieldDoneTouched];
    return YES;
}

#pragma mark -
#pragma mark UITextViewDelegate

- (void) textViewDoneTouched
{




    [self.site setValue:textView.text forIndex:selectedRow];

    [UIView animateWithDuration:0.3
                     animations:^{
                         CGRect f = textViewContainerView.frame;
                         f.origin.y = self.view.frame.size.height;
                         textViewContainerView.frame = f;
                     }];

    [textView resignFirstResponder];
    NSIndexPath *indexPath = [NSIndexPath indexPathForItem:selectedRow inSection:0];
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    self.tableView.userInteractionEnabled = YES;

    [self validateSiteData];
}


#pragma mark - UIActionSheetDelegate

- (void) actionSheet:(UIActionSheet *)actionSheet1 clickedButtonAtIndex:(NSInteger)buttonIndex
{

    if(buttonIndex == 0) {
        self.site.price = @"Free";
       // NSIndexPath *indexPath = [NSIndexPath indexPathForItem:4 inSection:0];

       // [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:100];
        //[textField resignFirstResponder];
       // [textView becomeFirstResponder];
        }
    else if(buttonIndex == 1) {
        self.site.price = @"Paid ($)";
       // NSIndexPath *indexPath = [NSIndexPath indexPathForItem:4 inSection:0];

      //  [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:100];
       // [textField resignFirstResponder];
         //[textView becomeFirstResponder];
        }


    NSIndexPath *indexPath = [NSIndexPath indexPathForItem:selectedRow inSection:0];
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

    [self validateSiteData];

}

回答1:


So, you'd like the iPhone's return key to go to the next field, like pressing Tab on a computer keyboard?

One minor note: I'd recommend using the default grey "return" key, not the blue "Done" key in your screenshot. "Done" is for when the user is done filling out the form and the keyboard should disappear; "return" is for going to the next field or row of text, as in Apple's Contacts app.

Like Apple's Contacts app, I'd also recommend that your UITextFields be in the same UITableViewCells as their labels (Category, Name...). I find the text field directly above the keyboard in your screenshot a little confusing. If you do that, then the following implementation of textFieldShouldReturn will make the next cell's text field into the first responder.

- (BOOL) textFieldShouldReturn:(UITextField*)textField {
    // Determine the row number of the active UITextField in which "return" was just pressed.
    id cellContainingFirstResponder = textField.superview.superview ;
    NSInteger rowOfCellContainingFirstResponder = [self.tableView indexPathForCell:cellContainingFirstResponder].row ;
    // Get a reference to the next cell.
    NSIndexPath* indexPathOfNextCell = [NSIndexPath indexPathForRow:rowOfCellContainingFirstResponder+1 inSection:0] ;
    TableViewCell* nextCell = (TableViewCell*)[self.tableView cellForRowAtIndexPath:indexPathOfNextCell] ;
    if ( nextCell )
        [nextCell.theTextField becomeFirstResponder] ;
    else
        [textField resignFirstResponder] ;
    return YES ;
}

Let me know if you'd like me to post the whole project.



来源:https://stackoverflow.com/questions/14582924/how-to-move-to-next-cell-row-in-table-view-with-textview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!