Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6144499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:39:35+00:00 2026-05-23T18:39:35+00:00

I’ve successfully embedded a UITextView inside a UITableViewCell, and most of the table is

  • 0

I’ve successfully embedded a UITextView inside a UITableViewCell, and most of the table is working fine. However, when I enable editing on the UITextView and start editing, the table shifts up too far, obscuring the cursor. Is there a way to control how far the tableview scrolls? Manually scrolling the view to the cell works, but the view still scrolls up before scrolling back down and into view.

Here is an example of what I mean:
editing a UITextField – the field is neatly placed directly above the keyboard.
http://imageshack.us/photo/my-images/13/textfield.png/

editing a UITextView – the field is placed significantly above the keyboard removing the toolbar from the keyboard doesn’t affect anything)
http://imageshack.us/photo/my-images/809/textview.png/

Here’s all the code that is relevant to the UITextView in the UITableViewController object:

- (void)viewDidLoad
{
    [super viewDidLoad];    

    self.navigationItem.rightBarButtonItem = self.editButtonItem;

    [[NSNotificationCenter defaultCenter] addObserver: self
                                             selector: @selector(keyboardWillShow:) 
                                                 name: UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver: self
                                             selector: @selector(keyboardWillHide:) 
                                                 name: UIKeyboardWillHideNotification object:nil];
}

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    viewTargetedForEditing = (UIView *)textView;
    return YES;
}

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    [self.navigationController setNavigationBarHidden:YES animated:YES];


    // shrink the textView to fit on-screen
    originalTextViewFrame = textView.frame;
    CGRect keyboardRect = [[keyboardUserinfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGFloat keyboardHeight = keyboardRect.size.height;


    CGRect newViewFrame = textView.frame;
    CGFloat spaceAboveKeyboard = self.containerView.frame.size.height - keyboardHeight;
    newViewFrame.size.height = (spaceAboveKeyboard < textView.frame.size.height) ? spaceAboveKeyboard : textView.frame.size.height;


    /* animate the calculations */

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:[[keyboardUserinfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]];

    textView.frame = newViewFrame;

    [UIView commitAnimations];



    // recalculate the keyboard height, in case we aren't in portrait mode
    CGFloat toolbarHeight;
    if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
        toolbarHeight = 44.0;
    } else {
        toolbarHeight = 32.0;
    }

    CGRect frame = textView.inputAccessoryView.frame;
    frame.size.height = toolbarHeight;
}

- (void)endTextViewEditing
{
    [viewTargetedForEditing resignFirstResponder];
}

- (void)textViewDidEndEditing:(UITextView *)textView
{
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

#pragma mark - Keyboard Notifications

- (void)keyboardWillShow:(NSNotification *)notification
{
    [keyboardUserinfo release];
    keyboardUserinfo = [[notification userInfo] retain];
    [self viewDidBeginEditing:viewTargetedForEditing];
}
- (void)keyboardWillHide:(NSNotification *)notification
{
    [keyboardUserinfo release];
    keyboardUserinfo = [[notification userInfo] retain];
    [self viewDidEndEditing:viewTargetedForEditing];
}

- (void)viewDidBeginEditing:(id)aView
{
    // called 2nd

    UITableViewCell *cell = (UITableViewCell *)[aView superview];
    [self.tableView scrollToRowAtIndexPath:[self.tableView indexPathForCell:cell] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
- (void)viewDidEndEditing:(id)aView
{   
    NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell *)[viewTargetedForEditing superview]];

    gallupAppDelegate *appDelegate = (gallupAppDelegate *)[[UIApplication sharedApplication] delegate];

    switch (indexPath.section) {
        case SectionDescription:
            if (![[(UITextField *)aView text] isEqualToString:self.plan.Description]) {
                self.plan.Description = [(UITextField *)aView text];
                [appDelegate saveManagedContext];
            }
            break;

        case SectionNotes:
            if (![[(UITextView *)aView text] isEqualToString:self.plan.Notes]) {
                self.plan.Notes = [(UITextView *)aView text];
                [appDelegate saveManagedContext];
            }
            break;

        case SectionLocation:
            if (![[(UITextField *)aView text] isEqualToString:self.plan.Location]) {
                self.plan.Location = [(UITextField *)aView text];
                [appDelegate saveManagedContext];
            }
            break;
    }
}

The TextViewCell is a subclass of UITableViewCell, and it is the cell that is giving me the problem with scrolling.Here’s the implementation:

@implementation TextViewCell

@synthesize contents=_contents;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _contents = [[UITextView alloc] initWithFrame:CGRectZero];
        [self addSubview:_contents];
        self.contents.font = [UIFont systemFontOfSize:17];
        self.contents.dataDetectorTypes = UIDataDetectorTypeAll;


        CGRect frame = CGRectMake(0, 0, self.window.frame.size.width, 44.0);
        UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
        UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(endTextViewEditing)];
        UIToolbar *textViewToolbar = [[UIToolbar alloc] initWithFrame:frame];
        textViewToolbar.barStyle = UIBarStyleBlackOpaque;
        [textViewToolbar setItems:[NSArray arrayWithObjects:spacer, done, nil]];

        self.contents.inputAccessoryView = textViewToolbar;
    }
    return self;
}

- (void)endTextViewEditing
{
    [self.contents resignFirstResponder];
}

#define LEFT_MARGIN 15
#define TOP_MARGIN 5
- (void)layoutSubviews
{
    [super layoutSubviews];

    CGFloat width = self.frame.size.width - (LEFT_MARGIN *2);
    CGFloat height = self.frame.size.height - (TOP_MARGIN *2);
    self.contents.frame = CGRectMake(LEFT_MARGIN, TOP_MARGIN, width, height);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    //[super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)dealloc
{
    [super dealloc];
}

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:39:35+00:00Added an answer on May 23, 2026 at 6:39 pm

    As it turns out, subclassing the UITableView and implementing the following fixed the problem:

    - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
    {
        [super setContentOffset:contentOffset animated:animated];
        return;
    
    
    
        static int i = 0;
        if (0 == i) {
            i++;
        } else {
            i = 0;
            [super setContentOffset:contentOffset animated:animated];
        }
        return;
    }
    

    Apparently the -setContentOffset:animated: message was sent 2x, and if the first one is allowed to run the second time round doesn’t do it’s job properly.

    Does anyone have any insite as to why this would fix the problem?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.