Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8165011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:26:28+00:00 2026-06-06T19:26:28+00:00

I am making a simple application that uses a NSSlider, which can be put

  • 0

I am making a simple application that uses a NSSlider, which can be put to it’s max or min value with two buttons.The undo manager shall track all changes and allow to undo/redo all changes made using these two buttons.
Here is the interface:

#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate>
{
@private
    NSUndoManager* undoManager;
}

@property (assign) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSSlider *slider;


- (IBAction)putToMax:(id)sender;
- (IBAction)putToMin:(id)sender;
- (void) setSliderValue: (float) value;

@end

Implementation:

#import "AppDelegate.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize slider = _slider;

- (NSUndoManager*) windowWillReturnUndoManager: (NSWindow*) window
{
    return undoManager;
}

- (IBAction)putToMax:(id)sender 
{
    float value= [_slider floatValue];
    [ [undoManager prepareWithInvocationTarget: self] setSliderValue: value];
    if(![undoManager isUndoing])
        [undoManager setActionName: @"Put to Max"];
    NSLog(@"%f value added to the stack",value);
    [_slider setFloatValue: 100.0];
}

- (IBAction)putToMin:(id)sender 
{
    float value= [_slider floatValue];
    [ [undoManager prepareWithInvocationTarget: self] setSliderValue: value];
    if(![undoManager isUndoing])
        [undoManager setActionName: @"Put to Min"];
    NSLog(@"%f value added to the stack",value);
    [_slider setFloatValue: 0.0];
}

- (void) setSliderValue: (float) value
{
    [_slider setFloatValue: value];
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
}

- (id) init
{
    self=[super init];
    if(self)
    {
        undoManager=[[NSUndoManager alloc]init];
    }
    return self;
}


@end

And a screenshot of the application:

enter image description here

The undo works fine, but I have problems with redo.

For example after launching the application:

  • I click on the put to max button.
  • Then menu Edit -> Undo put to max.

The slider goes back where it was.

But if I go to menu Edit -> Redo put to max, the slider doesn’t go back to it’s max position. And I don’t understand why.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:26:29+00:00Added an answer on June 6, 2026 at 7:26 pm

    When the Undo system performs an undo action, it expects you to register the redo actions using the same code as for undo, (except that the NSUndoManager knows it’s rewinding – but you should not care).

    So add the proper NSUndoManager calls in -setSliderValue:

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have an application I'm making that can be simply described as a
Hi I want to try making a simple application for android phones for which
Alright, here's my dillema. I am making a simple application with Qt Creator that
I’m making a sample application that uses MigLayout in a very cool way. Unfortunately
I'm making an application which uses OpenGL and currently store an array of objects
I am making simple application that will take hotel name and price of item,
I'm making a simple C# desktop application that searches into the log directories to
I'm writing a rather simple application that uses GWT, Hibernate and Google Guice (with
Hi I'm trying to create a simple music library for my application that uses
I am making a Android application which uses Contacts. The good thing is I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.