1

I've got a TextField that I'm trying to update the values as it progresses through running my code using KVC. Unfortunately I cannot seem to get anything to update past the initial value.

I've used the bindings on the button that launches the code, the TextField that I want to update and it just doesn't want to update. Please forgive me for the n00bish question but I've been searching online all day, going through tutorials, rewriting the code different ways and can't seem to figure out why this very simple tasks won't work.

Here is my KVC.h file:

#import <Foundation/Foundation.h>

@interface KVC : NSObject{
    NSString *_progressString;
}

@property (nonatomic, retain) NSString *progressString;
@end

Here is my App header file:

#import <Cocoa/Cocoa.h>
#import "KVC.h"

//UI Controls
@interface AppDelegate : NSObject <NSApplicationDelegate> 
{
    NSWindow *window;
    NSPersistentStoreCoordinator *__persistentStoreCoordinator;
    NSManagedObjectModel *__managedObjectModel;
    NSManagedObjectContext *__managedObjectContext;
    NSButton *_loadingExtracts;
    NSButton *_processStuff;
    NSProgressIndicator *_progressBar;
    KVC *myProgressString; 
}

@property (assign) IBOutlet NSWindow *window;

@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (assign) IBOutlet NSButton *loadingExtracts;
@property (assign) IBOutlet NSButton *processStuff;
@property (assign) IBOutlet NSProgressIndicator *progressBar;

- (IBAction)saveAction:(id)sender;
- (IBAction)loadingExtracts:(id)sender;
- (IBAction)processStuff:(id)sender;

@end

And finally, here is the function inside the code that I cannot get to update.

- (IBAction)processStuff:(id)sender 
{
    KVC *frickenHeck = [[KVC alloc] init];
    NSLog(@"Button Pressed - Processing Information");
    [myProgressString setValue:@"Testing" forKey:@"_progressString"];
    [_progressBar setUsesThreadedAnimation:YES];
    [_progressBar startAnimation:self];

    //Turn off Progress Bar
    [_progressBar stopAnimation:self];
    [frickenHeck setValue:@"Completed" forKey:@"_progressString"];
    //[_progressText setStringValue:@""];
}

(As you can see, I've tried updating 2 different ways and neither work. The allocation seems to set up the initial variable just fine, the Log shows I'm in the method, just can't get my label to update past the allocation).

Any thoughts or ideas would be greatly appreciated.

WrightsCS
  • 50,551
  • 22
  • 134
  • 186

1 Answers1

0

I am more of a iOS developer, so I am not 100% certain how some of the standards cross-over to the OSX side of things. Nevertheless,

You are saying that you are using KVC, like it is a framework providing a easy to use key-value coding scheme, which doesn't necessarily make sence. This appears to be a custom class you created called KVC.

In your KVC.m file did you @synthesize this variable?

@implementation KVC

@synthesize progressString = _progressString;

You have defined your object frickenHeck as class KVC which holds a property called progressString, that you are making available to other classes via this call. @property (nonatomic, retain) NSString *progressString;

Assuming you have synthesized the variable in your @implementation file, why don't you just call:

frickenHeck.progressString = @"Testing";

or

frickenHeck.progressString = @"Completed";

Sure you can set the variable via Key Value Coding, but not by setting to the private form of your class variable. Try:

[frickenHeck setValue:@"Completed" forKey:@"progressString"];

So, have you synthesized this variable? Or at least set a accessor setter/getter for the variable? You typically only want to do one or the other.

Header:

- (void)progressString;
- (NSString *)setProgressString:(NSString *)_string;

Implementation:

- (void)progressString {
     return _progressString;

}
- (NSString *)setProgressString:(NSString *)_string {

_progressString=_string;

}

Also to note that if you are going to be changing this variable a lot, you may want to use the NSMutableString form of the class, and set the @property declaration to copy. @property (nonatomic, copy) NSMutableString *progressString;

I hope some of this information assists you on your journey..

Mark

Mark Perkins
  • 215
  • 1
  • 8