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

  • Home
  • SEARCH
  • 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 8247001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:41:49+00:00 2026-06-07T22:41:49+00:00

Below is the code which I am using and working fine in simulator iOS

  • 0

Below is the code which I am using and working fine in simulator iOS 5+, but giving issue in simulator 4.3

UITextPosition *begin = [self.tvQuestion positionFromPosition:self.tvQuestion.beginningOfDocument offset:nrange.location];

Following is the error statement:

Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[UITextView beginningOfDocument]: unrecognized selector sent to instance 0x5586050’

Could somebody advice on this? Thanks in advance!

  • 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-06-07T22:41:51+00:00Added an answer on June 7, 2026 at 10:41 pm

    The UITextInput protocol includes a beginningOfDocument selector since iOS 3.2.
    But UITextView only adopted UITextInput since iOS 5.0. It was previously conforming to the UITextInputTraits protocol.

    Source: search for UITextView here http://developer.apple.com/library/ios/#releasenotes/General/iOS50APIDiff/index.html

    If you want it to work on iOS 4.x and later, you have to perform a check and do the computation by yourself on iOS 4:

    CGRect newRect = CGRectZero;
    
    if ([UITextView conformsToProtocol:@protocol(UITextInput)]) {
    
        // iOS 5 and later
        UITextPosition *begin = [self.tvQuestion positionFromPosition:self.tvQuestion.beginningOfDocument offset:nrange.location]; 
        UITextPosition *end = [self.tvQuestion positionFromPosition:begin offset:nrange.length]; 
        UITextRange *textRange = [self.tvQuestion textRangeFromPosition:begin toPosition:end]; 
        newRect = [self.tvQuestion firstRectForRange:textRange];
    
    } else {
    
        // iOS 3.2 to 4.3
        // Compute text position manually
    
    #define TEXT_VIEW_PADDING 8.f
    
        NSString *textContent = [self.tvQuestion.text substringToIndex:NSMaxRange(nrange)];
    
        NSDictionary *ctFontDescriptorAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                                    self.tvQuestion.font.familyName, kCTFontFamilyNameAttribute,
                                                    // Uncomment for bold fonts
                                                    // [NSDictionary dictionaryWithObjectsAndKeys:
                                                    // [NSNumber numberWithInt:kCTFontBoldTrait], kCTFontSymbolicTrait,
                                                    // nil], kCTFontTraitsAttribute,
                                                    nil];
    
        CTFontDescriptorRef ctFontDescriptor = CTFontDescriptorCreateWithAttributes((CFDictionaryRef)ctFontDescriptorAttributes);
        CTFontRef ctFont = CTFontCreateWithFontDescriptor(ctFontDescriptor, self.tvQuestion.font.pointSize, NULL);
    
        NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:textContent
                                                                             attributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                                     (id)ctFont, kCTFontAttributeName,
                                                                                     nil]];
    
        CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attributedText);
        CFRange globalRange = CFRangeMake(0, [attributedText length]);
    
        CGRect textRect = CGRectInset((CGRect){CGPointZero, self.tvQuestion.contentSize}, TEXT_VIEW_PADDING, TEXT_VIEW_PADDING);
        CTFrameRef frame = CTFramesetterCreateFrame(framesetter, globalRange, CGPathCreateWithRect((CGRect){CGPointZero, textRect.size}, NULL), NULL);
    
        CFArrayRef lines = CTFrameGetLines(frame);
        NSInteger nbLines = CFArrayGetCount(lines);
        CGPoint *lineOrigins = calloc(sizeof(CGPoint), nbLines);
        CTFrameGetLineOrigins(frame, CFRangeMake(0, 0), lineOrigins);
    
        CGFloat ascent = CTFontGetAscent(ctFont);
        CGFloat descent = CTFontGetDescent(ctFont);
        CGFloat leading = CTFontGetLeading(ctFont);
    
        if (leading < 0) {
            leading = 0;
        }
        leading = floor(leading + 0.5);
    
        CGFloat lineHeight = floor(ascent + 0.5) + floor(descent + 0.5) + leading;
        CGFloat firstLineYOffset = 0.f;
    
        for (NSInteger i = 0; i < nbLines; i++) {
    
            CTLineRef line = CFArrayGetValueAtIndex(lines, i);
            CFRange lineRange = CTLineGetStringRange(line);
            CGPoint lineOrigin = lineOrigins[i];
            CGFloat ascent, descent, leading, width;
            width = CTLineGetTypographicBounds(line, &ascent,  &descent, &leading);
    
            if (i == 0) {
                firstLineYOffset = lineOrigin.y;
            }
            lineOrigin.y = (lineOrigin.y - firstLineYOffset) * -1.f;
    
    
            if (nrange.location >= lineRange.location && nrange.location < lineRange.location + lineRange.length) {
    
                CGFloat secOffset;
                CGFloat startOffset = CTLineGetOffsetForStringIndex(line, nrange.location, &secOffset);
    
                CGFloat rectWidth;
                if (nrange.location + nrange.length <= lineRange.location + lineRange.length) {
                    CGFloat endOffset = CTLineGetOffsetForStringIndex(line, nrange.location + nrange.length, &secOffset);
                    rectWidth = endOffset - startOffset;
                } else {
                    rectWidth = width - 5 - startOffset;
                }
    
                newRect = (CGRect)
                {
                    {
                        lineOrigin.x + TEXT_VIEW_PADDING + startOffset,
                        lineOrigin.y + TEXT_VIEW_PADDING + i
                    }, {
                        rectWidth,
                        lineHeight
                    }
                };
    
                break;
            }
        }
    
        free(lineOrigins);
        CFRelease(frame);
        CFRelease(framesetter);
        CFRelease(ctFont);
        CFRelease(ctFontDescriptor);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the below code which is working fine in chrome, IE but
I am using blow code for join in nhibernate, which is working fine. But
I am using JQuery. I have below JQuery Code which working fine in Firefox,
I am using the below code to replace some text which is working fine.
I have a working JavaScript code below which dynamically creates JSON object using JSON.parse
I am using the below code to block the taskbar which is working perfectly.
i have got below code which is working fine: public abstract class Beverage {
Currently i'm using below code which works well. $(#topperAtBaseLevel:visible, #lowerAtBaseLevel:visible, #midAtBaseLevel).hide(); any optimised code?
I am using the below code to receive the message via serial port which
I have a sort function which was working fine but then I tried to

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.