Problem Dev Cocoa textField

Joined
Jun 26, 2015
Messages
5
Reaction score
0
Points
1
Hello,
I'm looking for a way to show you my cocoa dev code, to permit you to help me. My problem is that I did not succeed in refreshing a textfield.

Thanks.
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,770
Reaction score
2,110
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Welcome to Mac-Forums.

If you have code to share, then paste it here within [ CODE ] [ / CODE ] blocks, removing the extra spaces of course and people in the know will comment on it...
 
OP
N
Joined
Jun 26, 2015
Messages
5
Reaction score
0
Points
1
Thanks,
My code is :

AppDelegate.h
Code:
#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate>

{
    int fromValue;
    int toValue;
    int nombre;
    BOOL comptage;
}

@property (weak) IBOutlet NSTextField *champFrom;
@property (weak) IBOutlet NSTextField *champTo;
@property (weak) IBOutlet NSTextField *champAff;

- (IBAction)takeFrom:(id)sender;
- (IBAction)takeTo:(id)sender;

- (IBAction)start:(id)sender;
- (IBAction)stop:(id)sender;

- (void)updateUserInterface;
- (id) init;

@end



AppDelegate.m
Code:
#import "AppDelegate.h"

@interface AppDelegate ()

@property (weak) IBOutlet NSWindow *window;

@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
    [self init];
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
    // Insert code here to tear down your application
}

- (IBAction)takeFrom:(id)sender {
    fromValue = [sender intValue];
    //[self updateUserInterface];
}

- (IBAction)takeTo:(id)sender {
    toValue = [sender intValue];
    //[self updateUserInterface];
}

- (IBAction)start:(id)sender {
    nombre=fromValue;
    [self updateUserInterface];
    comptage=true;
    if ((fromValue<=toValue)&&(comptage==true)){
        while ((nombre<toValue)&&(comptage==true)) {
            nombre=nombre+1;
            [self updateUserInterface];
        }
    }
}

- (IBAction)stop:(id)sender {
    //nombre=toValue;
    comptage=false;
    [self updateUserInterface];
}

- (void)updateUserInterface {
    [self.champAff setIntValue:nombre];
}

- (id) init{
    self = [super init];
    if (self) {
        fromValue=0;
        toValue=0;
        nombre=0;
        comptage=true;
        return self;
    }
    else
        return nil;
}
@end

And I would like to refresh the textField to display 1,2,3,... and finally 1000, but i have : 1,1000.

Could you help me ?
 
Last edited by a moderator:

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
I may be reading this wrong (I dislike ObjC thoroughly) but it looks like instead of appending the value of "nombre", you're simply setting the value of the textfield to its value which eventually hits 1,000. Instead of setting the value to whatever nombre is set as, append the value of nombre to the value of the textfield.
 
OP
N
Joined
Jun 26, 2015
Messages
5
Reaction score
0
Points
1
I may be reading this wrong (I dislike ObjC thoroughly) but it looks like instead of appending the value of "nombre", you're simply setting the value of the textfield to its value which eventually hits 1,000. Instead of setting the value to whatever nombre is set as, append the value of nombre to the value of the textfield.

Thanks for your answer.
No, I think that you understand the problem ; but don't you think that the method updateUserInterface called in the while (of the start method) is enough to update the textField to the fresh value (2,3,...,1000) ?
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Yes, the updateUserInterface function (or whatever it's called in ObjC) is being called each time but in setting the value to the nombre variable, it's replacing the value in the textbox each time, not adding to it. In other words, you need to set the value of the box to what it was before plus the new number. See here.
 
OP
N
Joined
Jun 26, 2015
Messages
5
Reaction score
0
Points
1
No, finally you didn't understand ; I just want to have the number 1 display, and after I only want the number 2, etc... and I only want to display the number 1000.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top