NSTextView not editable text areas?

I have NSTextViewone that contains data for the user to edit, but I want to surround him with the header and footer of non-editable data to give the user an idea of ​​the context.

I don’t think I NSTextViewcan handle the concept of mixed editable / non-editable data, so I came up with a few ideas.

a) Use text attachments with a custom cell to draw headers and footers.

b) Have 3 NSTextViewwithin NSScrollView.

c) Use attributes to determine what cannot be edited, and use delegate methods to prevent editing, this is probably my favorite as it is probably the least intrusive.

Am I missing something, any better ideas?

+3
source share
1 answer

The NSTextView delegation method is textView: shouldChangeTextInRange: replacementString: will allow you to do this. You can "just say" NO "to change .;-)

Update / Development (November 2015)

To develop based on the comments on this answer, the idea is to use your own custom attributes in the attribute string , your textual editing view. In addition to the standard attributes , you can specify your own attribute name (any NSString) and a PLIST-compatible object as a value for this name.

, "uneditable", () @"TextIsEditableAttributeName" NSNumber BOOL YES NO: [NSNumber NO] @( NO ) ( - ObjC - : NSNumber), , , , @"TextIsEditableAttributeName".

, , , . NSData , . @"EditingLocked" - . , @"EditingLocked" NO . ( ) .

, , -textView:willChangeSelectionFromCharacterRanges:toCharacterRanges:, , "" . , "" , @"EditingLocked", .

, .

+7

Source: https://habr.com/ru/post/1723130/


All Articles