0

So far, i have only gotten one report of this crash:

'-[UITextView setTextContainerInset:]: unrecognized selector sent to instance 0x1d68e600'

and i'm not sure why this is happening. I'm unable to reproduce the issue. My actual line of code is this:

UITextView *someInfo = = [[UITextView alloc] initWithFrame:CGRectMake(x, y, 100, 30)];
someInfo.textContainerInset = UIEdgeInsetsMake(0, HORIZONTAL_PADDING, 0, HORIZONTAL_PADDING);

But i don't understand why it is saying the selector is not sent properly. I did also notice that the bug crashed on someone's iphone 4, when they were runnig ios 6.1.3. Is this something specific to pre iOS 7??

David T.
  • 18,561
  • 18
  • 61
  • 115

2 Answers2

1

Key points:

  1. Here it will not even compile if you are build your application in less than iOS 7.0 version. It will show an error of unrecognized selector sent to instance.

  2. But you have mention in your question that “I did also notice that the bug crashed on someone's iphone 4”. From that i can assume that you are creating build in iOS 7.0 or later.

  3. The issue is because of the backward compatibility. You need to take care of this type of things when you allow your application to run on earlier version.

You have to implement conditions to check version compatibility.

#if __IPHONE_6_0 || __IPHONE_6_1

#else

#endif

EDIT:

For Pre iOS 7.0 you need to use NSAttributedString and NSMutableParagraphStyle.

For the left and right margins don't add your plain text right away but use an NSAttributedString instead with properly set left and right indents with an NSMutableParagraphStyle:

NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.headIndent = 20.0;
paragraphStyle.firstLineHeadIndent = 20.0;
paragraphStyle.tailIndent = -20.0;

NSDictionary *attrsDictionary = @{NSFontAttributeName: [UIFont fontWithName:@"TrebuchetMS" size:12.0], NSParagraphStyleAttributeName: paragraphStyle};
textView.attributedText = [[NSAttributedString alloc] initWithString:myText attributes:attrsDictionary];

Above code is straight from this answer:

Set padding in UITextView

Community
  • 1
  • 1
Kampai
  • 21,517
  • 19
  • 87
  • 90
  • 1
    this is not entirely accurate, it WILL compile pre-ios 7, which is why i had this issue in production. however, you are correct that the problem is compatibility – David T. Nov 04 '14 at 19:43
  • so what is the proper way to set content inset pre iOS 7? – David T. Nov 04 '14 at 19:55
0

Per Apple's Documentation, that property is only available in iOS 7+.

AdamPro13
  • 6,534
  • 2
  • 26
  • 27