nsundomanager

Core Data and NSOperation

眉间皱痕 提交于 2019-12-03 10:05:00
问题 I'm currently working with an NSPersistentDocument subclass that uses NSOperation to import data in the background. As per the documentation, I'm observing the NSManagedObjectContextDidSaveNotification after saving in the background task and propagating the notification to the NSManagedObjectContext in the main thread using -mergeChangesFromContextDidSaveNotification: . Everything works fine, but it presents a weird workflow for a user who's importing data into a new document. They need to

Implementing NSUndoManager

。_饼干妹妹 提交于 2019-12-03 09:15:48
I'm having a hard time implementing the NSUndoManager, I tried reading the apple documentation on it, but I cant figure it out. This is what I have tried so far. I have created an app that draws lines by connecting two points in an array, I implemented an undo method by removing the last object, but cant figure out how to implement the redo, I stumbled upon NSUndoManager and started reading its documentation, but I dont know how to apply it to my issue. Heres the code that I have at the moment -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSUInteger taps = [[touches

Difficulty implementing NSUndoManager redo function

旧时模样 提交于 2019-12-03 07:52:20
问题 I'm trying to implement an NSUndoManager in my iOS app. I got the undo functionality to work, but not the redo part. I'm quite new to iOS development and this is the first time that I've used NSUndoManager so it's probably something trivial. My app is a painting/note taking app, I have a undo/redo stack with the last ten UIImage s (I don't know if this is the most efficient way) in an array. When the user makes changes to the current image, the old image is pushed onto the stack, and the

How can I replace text in UITextView with NSUndoManager support?

吃可爱长大的小学妹 提交于 2019-12-03 02:50:45
I want to be able to replace some text in an UITextView programatically, so I wrote this method as an UITextView category: - (void) replaceCharactersInRange:(NSRange)range withString:(NSString *)newText{ self.scrollEnabled = NO; NSMutableString *textStorage = [self.text mutableCopy]; [textStorage replaceCharactersInRange:range withString:newText]; //replace text but undo manager is not working well [[self.undoManager prepareWithInvocationTarget:self] replaceCharactersInRange:NSMakeRange(range.location, newText.length) withString:[textStorage substringWithRange:range]]; NSLog(@"before replacing

Core Data and NSOperation

…衆ロ難τιáo~ 提交于 2019-12-03 01:48:14
I'm currently working with an NSPersistentDocument subclass that uses NSOperation to import data in the background. As per the documentation, I'm observing the NSManagedObjectContextDidSaveNotification after saving in the background task and propagating the notification to the NSManagedObjectContext in the main thread using -mergeChangesFromContextDidSaveNotification: . Everything works fine, but it presents a weird workflow for a user who's importing data into a new document. They need to save an empty document before doing the import (otherwise the -save: fails because the document hasn't

Difficulty implementing NSUndoManager redo function

折月煮酒 提交于 2019-12-02 21:18:06
I'm trying to implement an NSUndoManager in my iOS app. I got the undo functionality to work, but not the redo part. I'm quite new to iOS development and this is the first time that I've used NSUndoManager so it's probably something trivial. My app is a painting/note taking app, I have a undo/redo stack with the last ten UIImage s (I don't know if this is the most efficient way) in an array. When the user makes changes to the current image, the old image is pushed onto the stack, and the first image in the array is removed if the array already has ten objects. I have a int instance variable

Using NSUndoManager, how to register undos using Swift closures

戏子无情 提交于 2019-12-01 23:40:24
问题 I am trying to grok how to use NSLayoutManager using Swift closures. I can successfully register an undo as follows: doThing(); undoManager?.registerUndoWithTarget(self, handler: { _ in undoThing(); } undoManager?.setActionName("do thing") Of course I need to support redo which amounts to an undo of an undo. I can do that: doThing(); undoManager?.registerUndoWithTarget(self, handler: { _ in undoThing(); undoManager?.registerUndoWithTarget(self, handler: { _ in doThing(); } undoManager?

Using NSUndoManager, how to register undos using Swift closures

喜你入骨 提交于 2019-12-01 21:12:14
I am trying to grok how to use NSLayoutManager using Swift closures. I can successfully register an undo as follows: doThing(); undoManager?.registerUndoWithTarget(self, handler: { _ in undoThing(); } undoManager?.setActionName("do thing") Of course I need to support redo which amounts to an undo of an undo. I can do that: doThing(); undoManager?.registerUndoWithTarget(self, handler: { _ in undoThing(); undoManager?.registerUndoWithTarget(self, handler: { _ in doThing(); } undoManager?.setActionName("do thing") } undoManager?.setActionName("do thing") But now I need to support an undo of the

Using NSUndoManager and .prepare(withInvocationTarget:) in Swift 3

六月ゝ 毕业季﹏ 提交于 2019-12-01 04:11:58
I am migrating an Xcode 7 / Swift 2.2 mac OS X project to Xcode 8 / Swift 3, and I have run into a problem using undoManager in my view controller class, MyViewController, which has a function undo. In Xcode 7 / Swift 2.2, this worked fine: undoManager?.prepareWithInvocationTarget(self).undo(data, moreData: moreData) undoManager?.setActionName("Change Data) In Xcode 8 / Swift 3, using the recommended pattern from https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/AdoptingCocoaDesignPatterns.html this should be changed to: if let target = undoManager?

How to name Undo menu entries for Core Data add/remove items via bindings and NSArrayController?

别来无恙 提交于 2019-12-01 01:34:41
I have a NSTableView populated by a Core Data entity and Add Item / Remove Item buttons all wired with a NSArrayController and bindings in Interface Builder. The Undo/Redo menu items can undo or redo the add / remove item actions. But the menu entries are called only „Undo“ resp. „Redo“. How can i name them like „Undo Add Item“, „Undo Remove Item“, etc. (I am aware, something similar was asked before, but the accepted answers are either a single, now rotten link or the advice to subclass NSManagedObject and override a method that Apples documentation says about: "Important: You must not