Wednesday, 18 September 2013

textField stringValue returns null when I make it a default for an attribute of an entity in core data

textField stringValue returns null when I make it a default for an
attribute of an entity in core data

Please help:
I am trying to use text fields as inputs by making them change the default
attribute of an entity before adding that entity to my table view. So if
you typed "item 1" in the text field then the next entity would appear
pre-populated with the "title" column's attribute reading "item 1."
Unfortunately, when I try to use [textField stringValue] to set the string
of the default it just returns null at run time!
What am I missing? Thank you
My Entity .h
// ItemEntity.h
#import <Foundation/Foundation.h>
@interface ItemEntity : NSManagedObject{
}
-(NSString *) titleValue;
@end
.m
// ItemEntity.m
#import "ItemEntity.h"
#import "MyManager.h"
@implementation ItemEntity
-(NSString *)titleValue{
MyManager *sharedManager = [MyManager sharedManager];
NSString *nam = [NSString stringWithFormat:@"%@",
sharedManager.titleText]; //titleText from MyManager;
return nam;
}
@end
My Manager Object .h
// MyManager.h
#import <Foundation/Foundation.h>
@interface MyManager : NSObject {
NSString *titleText;
@public
IBOutlet NSTextField *titleLabel;
}
@property (nonatomic, retain) NSString *titleText;
+ (id)sharedManager;
@end
Here's where the problem is I think .m
// MyManager.m
#import "MyManager.h"
@implementation MyManager
@synthesize titleText;
+ (id)sharedManager {
static MyManager *sharedMyManager = nil;
@synchronized(self) {
if (sharedMyManager == nil)
sharedMyManager = [[self alloc] init];
}
return sharedMyManager;
}
- (id)init {
if (self = [super init]) {
titleText = [NSString stringWithFormat:@"default"];
}
return self;
}
- (NSString *)titleText;{ //this is being called - but still returns (null)
NSString *y = [[NSString alloc] initWithFormat:@"why is this returning
(null)?, %@", [titleLabel stringValue]];
return y;
}
@end

No comments:

Post a Comment