nsundomanager

undo all changes made in the child view controller

99封情书 提交于 2019-11-30 12:33:25
问题 There are two entities: Author and Book. Author has an attribute authorName and a to-many relationships books. Book has several attributes and a relationship author. There is a view controller (VCAuthor) to edit an Author object. The child view controller(VCBook) is to edit books of the author. There is only one managedobjectcontext. In the VCBook class i group the undomanager as following -(void)viewDidLoad { NSUndoManager *anUndoManager = [[NSUndoManager alloc] init]; [self.book

Undo/redo with a UITextView (iOS/iPHone)

不打扰是莪最后的温柔 提交于 2019-11-30 05:31:06
I have a view where a UITextView always has focus. What I want to do is extend the built-in undo/redo behavior to support undo/redo for when I programmatically set the text (e.g., for when I clear it, by setting it to @""). Since only the firstResponder gets undo/redo events, I thought I'd simply use the UITextView's undoManager property to create my invocations. e.g., // Before clearing the text... [[self.myTextView.undoManager prepareWithInvocationTarget:self] undoClear:self.myTextView.text]; [self.myTextView.undoManager setActionName:@"Clear"]; // ... -(void)undoClear:(NSString *

Cocoa: looking for a general strategy for programmatic manipulation of NSTextView storage without messing up undo

我的梦境 提交于 2019-11-30 02:00:20
I am writing a special-purpose text editor in cocoa that does things like automatic text substitution, inline text completions (ala Xcode ), etc. I need to be able to programmatically manipulate the NSTextView ’s NSTextStorage in response to 1) user typing, 2) user pasting, 3) user dropping text. I have tried two different general approaches and both of them have caused the NSTextView ’s native undo manager to get out of sync in different ways. In each case, I am only using NSTextView delegate methods. I have been trying to avoid subclassing NSTextview or NSTextStorage (though I will subclass

“[NSBigMutableString substringWithRange:]: Range {0, 10} out of bounds; string length 9” error with Undo

早过忘川 提交于 2019-11-29 14:01:46
My app crashes when I try to do undo on UISearchBar . In my app I have code to prevent entering a '%' sign on the search bar and for doing this it replaces a % to @"" in textDidChange method as below: - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { self.searchBar.text = [searchText stringByReplacingOccurrencesOfString:@"%" withString:@""]; } So if I type text "abc%xyz", the final text visible on search bar would be 'abcxyz'. No when I click undo, I see 'xyz' gets cleared and I still see 'abc' on the search bar instead of clearing 'abcxyz' all at one go. Now if

Undo/redo with a UITextView (iOS/iPHone)

谁说我不能喝 提交于 2019-11-29 04:16:42
问题 I have a view where a UITextView always has focus. What I want to do is extend the built-in undo/redo behavior to support undo/redo for when I programmatically set the text (e.g., for when I clear it, by setting it to @""). Since only the firstResponder gets undo/redo events, I thought I'd simply use the UITextView's undoManager property to create my invocations. e.g., // Before clearing the text... [[self.myTextView.undoManager prepareWithInvocationTarget:self] undoClear:self.myTextView.text

How do I register UndoManager in Swift?

Deadly 提交于 2019-11-28 09:15:34
How do I use UndoManager (previously NSUndoManager ) in Swift? Here's an Objective-C example I've tried to replicate: [[undoManager prepareWithInvocationTarget:self] myArgumentlessMethod]; Swift, however, seems to not have NSInvocation , which (seemingly) means I can't call methods on the undoManager that it doesn't implement. I've tried the object-based version in Swift, but it seems to crash my Playground: undoManager.registerUndoWithTarget(self, selector: Selector("myMethod"), object: nil) However it seems to crash, even with my object accepts an argument of type AnyObject? What's the best

“[NSBigMutableString substringWithRange:]: Range {0, 10} out of bounds; string length 9” error with Undo

依然范特西╮ 提交于 2019-11-28 07:36:40
问题 My app crashes when I try to do undo on UISearchBar . In my app I have code to prevent entering a '%' sign on the search bar and for doing this it replaces a % to @"" in textDidChange method as below: - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { self.searchBar.text = [searchText stringByReplacingOccurrencesOfString:@"%" withString:@""]; } So if I type text "abc%xyz", the final text visible on search bar would be 'abcxyz'. No when I click undo, I see 'xyz'