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 8951605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:42:08+00:00 2026-06-15T13:42:08+00:00

I am trying to detect what formatting will be applied to new text being

  • 0

I am trying to detect what formatting will be applied to new text being entered by the user. Meaning the cursor has a position, but no text selection (i.e. length = 0). Every time I try to query typingAttributes, even if it’s just to log, the app crashes.

Thread 1:EXC_BAD_ACCESS (code=2, address=0x4)

In the Debug Navigator the last thing that happens is:

WebCore::Frame::styleAtSelectionStart() const

And just before that, I see

-[UITextView typingAttributes]

If I log with a selectedRange.length greater than 0, it seems to be fine. I’ve tried running with Zombies and Guard Malloc enabled, but am not seeing anything.

In my test project, the crash occurs as soon as the UITextView becomes firstResponder:

- (void)textViewDidChangeSelection:(UITextView *)textView
{
    [self updateFormatButtons];
}

Which calls to check the attributes:

- (void)updateFormatButtons
{    
    UITextView *problemTextView = [self synopsisTextView];
    NSRange selectedRange = [self getSelectedTextRange];
    if (selectedRange.length == 0) // No text selected
    {
     // HELP - Why does the following line cause a crash?
     // NSLog(@"textViewFormatting options: %@", [problemTextView typingAttributes]);
    }
    else
    {
       NSLog(@"Some text selected"); // Fine here
       NSLog(@"textViewFormatting options: %@", [problemTextView typingAttributes]);
    }
}

based on the selected range:

- (NSRange)getSelectedTextRange
{ 
    NSRange rangeToReturn = NSMakeRange(NSNotFound, 0);
    UITextView *textView = [self synopsisTextView];
    if ([textView isFirstResponder])
    {
        rangeToReturn = [textView selectedRange];
    }
    return rangeToReturn;
}

Suggestions appreciated.

  • 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-15T13:42:10+00:00Added an answer on June 15, 2026 at 1:42 pm

    The issue appears to have been that when the text view’s selection changes, the contents of the typingAttributes dictionary are cleared automatically. So having the dictionary queried immediately was causing some kind of conflict. Putting a delay before calling seems to have addressed it:

    [self performSelector:@selector(updateFormatButtons) withObject:nil afterDelay:0.15];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to detect if a user on my page has cookies enabled
I'm trying to detect when the browser has stopped being resized. The following works,
I am trying to detect if a text input field has any character that
Trying to detect when a user clicks Cancel but the $_POST on using var_export($_POST)
I'm trying to detect whether the shift key is being pressed while the cursor
I'm trying to detect when the user presses certain keys in a text box
I am trying to detect whether a block of text (from a textarea) contains
I'm trying to detect the position of the browser's scrollbar with JavaScript to decide
I'm trying to detect if the user is already in a phone call when
I'm trying to detect the distance the mouse has moved, in pixels. I am

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.