मैं एक NSTextView और एक बटन, TextView के लिए एक NSTextViewDelegate प्रदान की के साथ एक सरल डेमो एप्लिकेशन बनाया है और एक कार्रवाई कहा: अगर मैं हाथ से पाठ बदलने के लिए, समस्याओं के बिनाटेक्स्ट के प्रोग्रामेटिक परिवर्तन के साथ पूर्ववत/दोबारा कैसे कार्यान्वित करें NSTextView के वॉल्यूम?
- (IBAction)actionButtonClicked:(id)sender {
NSString *oldText = [[[self.textView textStorage] string] copy];
NSString *newText = @"And... ACTION!";
[[self.textView undoManager] registerUndoWithTarget:self.textView
selector:@selector(setString:)
object:oldText];
[[self.textView undoManager] setActionName:@"ACTION"];
[self.textView setString:newText];
}
पूर्ववत करें/फिर काम करता है। लेकिन अगर मैं क्रिया विधि के साथ पाठ को पूर्ववत करता हूं, तो अपेक्षित कार्यों को पूर्ववत करें, लेकिन फिर से काम नहीं करता है (कुछ भी नहीं होता है) और पूर्ववत प्रबंधक को स्कैम्बल किया जाता है ...
ठीक - NSTextView के साथ समस्याओं से बचने के लिए मैंने बनाया एक मॉडल वर्ग, एनएसटीएक्स्टव्यू को बाध्य करता है और मॉडल को पूर्ववत/फिर से ले जाता है, लेकिन यह पहले जैसा ही व्यवहार दिखाता है - मैं क्या गलत कर रहा हूं - यह आसान होना चाहिए, है ना?
#import "GFTextStore.h"
@implementation GFTextStore
@synthesize textVal = textVal_;
-(void)changeText{
if (!undoMan_) {
undoMan_ = [[[NSApplication sharedApplication] mainWindow] undoManager];
}
NSAttributedString *oldText = [self.textVal copy];
NSString *tempStr = [[oldText string] stringByAppendingFormat:@"\n%@",[[NSCalendarDate date]description]];
NSAttributedString *newText = [[NSAttributedString alloc] initWithString:tempStr];
[self setTextVal:newText];
[undoMan_ registerUndoWithTarget:self
selector:@selector(setTextVal:)
object:oldText];
[undoMan_ setActionName:@"ACTION"];
}
@end
धन्यवाद रॉब, लेकिन यह मेरी समस्या का समाधान नहीं करता है। NSTextView के साथ समस्याओं से बचने के लिए मैंने कुछ बदलाव किए और मॉडल को पूर्ववत/फिर से ले जाया - संपादित प्रश्न देखें ... – user808667