Re: NSTextField recieves string but does not display it?
Re: NSTextField recieves string but does not display it?
- Subject: Re: NSTextField recieves string but does not display it?
- From: Erik Stainsby <email@hidden>
- Date: Sun, 05 Feb 2012 00:18:54 -0800
On 2012-02-04, at 8:38 PM, Quincey Morris wrote:
> This is all very code-smelly.
Here is a longer and more complete explanation of the circumstances.
MainMenu.xib
web browser window (A)
object references to App Delegate, Web Delegate and Rule Editor (WC)
The web delegate implements the following UIDelegate method:
- (NSArray *)webView:(WebView *)sender contextMenuItemsForElement:(NSDictionary *)element
defaultMenuItems:(NSArray *)defaultMenuItems {
// - (NSString*) selectorForDOMNode:(DOMNode*)node;
// returns the CSS selector - not an Obj-C selector
NSString * nodeSelector = [self selectorForDOMNode:[element objectForKey:WebElementDOMNodeKey]];
NSMenuItem * item1 = [[NSMenuItem alloc] initWithTitle:@"Set Action selector"
action:@selector(quickSetActionSelector:)
keyEquivalent:@""];
return [NSArray arrayWithObjects:item1,nil]; // there will be more menu cases later
}
=====
The web browser instantiates a subclassed WebView which declares & implements:
@interface RSSWebView : WebView
@property (retain) IBOutlet RSSRuleEditorController * ruleEditor;
- (IBAction) quickSetActionSelector:(id)sender;
@end
@implementation RSSWebView
@synthesize ruleEditor;
- (IBAction) quickSetActionSelector:(id)sender {
NSString * nodeSelector = [sender respresentedObject];
if( nodeSelector != nil) {
[ruleEditor setActionSelectorStringValue:nodeSelector];
}
}
@end
====
The Rule Editor is a WindowController initialized in the AppDelegate:
- (void) applicationWillFinishLaunching:(NSNotification *)notification {
NSLog(@"%s- [d] %@", __PRETTY_FUNCTION__, __LINE__, @"");
// this is a secondary window
editorController = [[RSSRuleEditorController alloc] init];
[[editorController window] makeKeyAndOrderFront:self];
}
The RSSWebView ruleEditor is connected to this editorController in IB.
The RUule Editor implements this method:
- (void) setActionSelectorStringValue:(NSString*)string {
// string is the nodeSelector
[[actionForms objectAtIndex:1] setActionSelectorString:string];
}
====
The class RSSRuleEditorController : NSWindowController employs view swapping.
RSSRuleEditorController has a mutable array holding a collection of view controllers,
which inherit from RSSEditorForm : NSViewController
The views which are owned by the members of the collection are input forms.
The test case is RSSActionForm : RSSEditorForm
This view currently hosts a single input field: NSTextField * actionSelector.
@interface RSSActionForm : RSSEditorForm
@property (retain) IBOutlet NSTextField * actionSelector;
- (void) setActionSelectorString:(NSString*) string;
@end
@implementation RSSActionForm
@synthesize actionSelector;
- (void) setActionSelectorString:(NSString*)nodeSelector {
NSLog(@"%s- [d] %@", __PRETTY_FUNCTION__, __LINE__, nodeSelector);
// Again, this is the CSS selector, not an Obj-C selector
if( nodeSelector != nil ) {
[[[self view] window] makeMainWindow];
[actionSelector setStringValue: nodeSelector];
[[self view] setNeedsDisplay:YES];
NSLog(@"%s- [d] %@", __PRETTY_FUNCTION__, __LINE__, [actionSelector stringValue]);
}
}
@end
====
To reiterate my problem, although the string which is set in this last method - setActionSelectorString has the correct value,
and reading it back after setting returrns that same value, the NSTextField * actionSelector (linked in IB) does not reflect the value in the UI.
Until I tried having teh ActionForm view controller call [[[self view] window] makeMainWindow] the call to [actionSelector setStringValue:nodeSelector] had no effect. This is what leads me to wonder if there is still something I need to do vis-à-vis the window 1 / window 2 relationship that I have not yet understood.
I remain perplexed.
~ Erik
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden