带有UITextView的iOS 7 UITableViewCell隐藏在键盘后面

时间:2013-09-20 19:39:29

标签: uitableview uitextview ios7

所以我在iOS 7中遇到了一些问题,在iOS 6中运行起来相当不错(我知道这说得很多,但这个很奇怪)。所以无论如何,我有一个Storyboard应用程序,TableView有一些Prototype单元格,一个部分有几个标签,然后是TextView用于输入响应。现在在iOS6中,当用户点击TextView时,表格会滚动以便为键盘上方的TextView腾出空间,但现在在iOS 6中(并且仅在4s iphone上,因为它有较小的屏幕)键盘滑动向上并且TableView仅滑动到足以使整个TableViewCell仍然可见,这使得TextView位于键盘后面的中间位置。这变得很麻烦,因为在输入单行文本后,用户不知道输入了什么,因为TextView被键盘阻挡了。由于TableView仅滚动足以使Cell和Header可见,因此在该部分的第一个单元格中更糟糕。我不知道看到代码是否会有所帮助,但我会在下面发布它(默认情况下,Cell的高度足以显示标签,然后当用户点击单元格时,高度会在该单元格上展开到揭示标签下面的TextView和Buttons

if ([indexPath section] == 1) {
        if ([btrArray count] > 0) {
            BTRCustomCell *btrCell = [tableView dequeueReusableCellWithIdentifier:@"BTRCell"];



            //Check if BTR Row has been selected to expand View
            if (row == btrSelectedRow) {
                CGRect extended = btrCell.reasonLbl.frame;
                extended.size.height = 70;
                btrCell.reasonLbl.frame = extended;
                btrCell.responseTV.hidden = NO;
                btrCell.ackButton.hidden = NO;
                btrCell.replyButton.hidden = NO;
            }
            else {
                CGRect normal = btrCell.reasonLbl.frame;
                normal.size.height = 30;
                btrCell.reasonLbl.frame = normal;
                btrCell.responseTV.hidden = YES;
                btrCell.ackButton.hidden = YES;
                btrCell.replyButton.hidden = YES;
            }

//leaving out the lines that just add text to labels
btrCell.responseTV.textColor = [UIColor lightGrayColor];
            [[btrCell.responseTV layer] setBorderColor:[[UIColor lightGrayColor] CGColor]];
            [[btrCell.responseTV layer] setBorderWidth:2.3];
            [[btrCell.responseTV layer] setCornerRadius:15];
            btrCell.responseTV.tag = kBTRTextView + row;
            btrCell.responseTV.delegate = self;

            //Add Keybar to TextView
            UIToolbar *keyBar = [[UIToolbar alloc] init];
            [keyBar setTintColor:MobileThemeColor];
            [keyBar sizeToFit];

            UIBarButtonItem *flexButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
            UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(resignKeyboard:)];
            doneButton.tag = kBTRDoneButton + row;
            NSArray *itemArray = [NSArray arrayWithObjects:flexButton, doneButton, nil];
            [keyBar setItems:itemArray];

            [btrCell.responseTV setInputAccessoryView:keyBar];

            //Add Targets To Buttons
            [btrCell.ackButton addTarget:self action:@selector(AcknowledgeButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
            btrCell.ackButton.tag = kBTRAckButton + row;
            [btrCell.replyButton addTarget:self action:@selector(ReplyButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
            btrCell.replyButton.tag = kBTRReplyButton + row;

            return btrCell;

我不太确定如何解决这个或导致它的原因。我正在重新编写应用程序,因为原版是为iOS3构建的,然后只是进行了少量更新以支持iOS6,因此ARC没有被使用,故事板和自动布局都不是更好使用应用程序的方式,所以这个代码从上一个版本复制到这个代码,但就像我说它在iOS7之前工作得很好。我不知道它是否只是iOS7中新行为的一部分,它不是一直向上滚动TableView来查看TextView或者我在设置中做错了什么,所以任何帮助都会很棒。

1 个答案:

答案 0 :(得分:0)

1)在.h文件中,@interface MyViewController () <UITextViewDelegate>

2)yourTextView.delegate = self;

3)使用此委托方法滚动查看表格

-(void) textViewDidBeginEditing:(UITextView *)textView
{

    if ([textView isEqual:yourTextView]) 
    {

        [tableview_WardList scrollToRowAtIndexPath:indexPathOfCellContainigTextview atScrollPosition:UITableViewScrollPositionTop animated:YES];

    }

}

当textview的编辑开始时,表格将向上滚动。请务必传递包含textview的单元格的索引路径。

相关问题