I'm working with an NSDatePicker and an NSTextField to update the text field whenever the NSDatePicker's value changes.
In Objective-C, I would use this method:
datePicker addTarget:self
action:#selector(dateChanged:)
forControlEvents:UIControlEventValueChanged
I've converted this method into the following AppleScriptObjC code:
datePicker's addTarget_action_forControlEvents_(me, ¬
#selector(dateChanged_), ¬
(current application's UIControlEventValueChanged))
However, this causes the build to fail. In place of #selector(dateChanged_), I've also tried "#selector(dateChanged:)", "#selector(dateChanged_)", and dateChanged_; no luck so far.
What is the correct way to convert this method to AppleScriptObjC?
Not tried, but it should be
datePicker's addTarget_action_forControlEvents_(me, "dateChanged:", (current application's UIControlEventValueChanged))
Related
I have a problem.
I have an NSObjectController called "mapController" and I want to put some defaults when the object is created. I do this inside the windowControllerDidLoadNib method of my document, as suggested by the docs. But…
if (![mapController content]){ // No map defined yet.
[mapController add: self]; // This should create the instance.
NSLog(#"%#",[mapController content]); // Gives NULL.
I tried:
BOOL ok = [mapController fetchWithRequest:nil merge:NO error:nil];
NSLog(#"%#",[mapController content]); // Gives NULL.
The content of mapController is in the Core Data "scratch pad" but I can't access it. I have to set one of its attributes like this:
[[mapController content] setValue:[matrix colorReference] forKey:#"mapData"];
This gives no error, the file is marked as changed, but it I test the value:
NSLog(#"%#",[mapController content]); // Gives NULL.
When the heck it the controller's content really HERE? Something appears on the screen but… what actually? Reading the docs doesn't help me…
OK, I found the answer in the docs:
add: Creates a new object and sets it as the receiver’s content object.
Discussion
Creates a new object of the appropriate entity (specified by
entityName) or class (specified by objectClass)—see newObject—and sets
it as the receiver’s content object using addObject:.
Special Considerations
Beginning with Mac OS X v10.4 the result of this method is deferred
until the next iteration of the runloop so that the error presentation
mechanism can provide feedback as a sheet.
That's why
[[mapController content] setValue:[matrix colorReference] forKey:#"mapData"];
worked fine when called elsewhere in the app. It was a few iterations later…
Well… maybe this post will save you a couple of hours you could use to sleep longer.
Regards,
Bernard
I don't think its your mapController, I think it is your NSLog. Try this:
NSLog(#"%#", mapController);
also try getting simple data from the content, like the float value of the CGColorRef so you can use other formatters like %f.
I would have tested this but I cannot seem to create an instance of NSObjectController because it is an undeclared identifier. What framework is it defined in? Did you have to #import anything?
I'm attempting to implement an NSSegmentedControl button in my IB.
I have it connected to - (IBAction)editCart:(id)sender;
Also, it is connected to NSSegmentedControl *editCartButton;
The first "segment" is a "-" button to decrease the cart value.
The second "segment" is a "+" button to increase the cart value.
When I attempt to use the "sender" value like so: [sender selectedSegment], I get an error:
-[NSTableView selectedSegment]: unrecognized selector sent to instance 0x100622aa0
My button is located inside an NSTableView.
I've also tried: [[editCartButton cell] selectedTag]
When I run it through my conditions, it always returns a value of (null).
I would like to retrieve the specific tags of 0 and 1 I'm expecting to get, but can't find the right actions.
Help appreciated greatly, thanks.
This:
-[NSTableView selectedSegment]: unrecognized selector
sent to instance 0x100622aa0
basically tells you that the sender is not the NSSegmentedControl you think it is. The sender is an NSTableView. So either you wired things up the wrong way, or you have a severe memory management problem where the NSSegmentedControl is deallocated, and an NSTableView is currently to be found at its memory location.
In -(IBAction)editCart:(id)sender you could add a line:
NSLog(#"editCart, sender = %#",sender);
to confirm this. You can drop NSLog lines like this in other places in your code, to verify your ideas about what should be happening.
in IBAction try replacing (id) with (UISegmentedControl *)
I had a similar problem when working on updating Seashore (A port of GIMP to native OS X APIs).
First, you have to get NSSegmentedControl's cell object:
NSSegmentedControl *segControl = ...
NSSegmentedCell *segCell = [segControl cell];
Then, you set the tag for the segment you want to modify:
[segCell setTag:200 forSegment:2];
More info is available in Apple's documentation.
I'm trying to code a simple UITextField and I have a simple question:
Im using this to 'empty' the UITextField:
-(IBAction)editbegin{
campo1.text="";
}
The problem is: want to use this function in more than one TextField. So, how can I 'grab' the object, so I can get the 'text'? Already tried 'self.text', but it returns the view.
Thanks.
Check out the UITextField documentation. It looks like you are trying to "reinvent" the wheel.
If all you want to do is clear the textfield once a user begins editing, there is a function for that.
When creating your text field, just set:
textField.clearsOnBeginEditing = YES;
The same option is also available on Interface Builder if that's what you are using.
Specific documentation link here http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UITextField_Class/Reference/UITextField.html#//apple_ref/occ/instp/UITextField/clearsOnBeginEditing
Include the "sender" property.
-(IBAction)editbegin:(id)sender{
sender.text=#"";
}
Edit: Apparently you need to cast it? I thought you could send any message to id. I guess this is better code, anyway.
-(IBAction)editbegin:(id)sender{
UITextField *field = (UITextField *)sender;
field.text=#"";
}
I'm just getting started with Objective-C and I'm writing a simple application.
I made two outlets :
wnd - main window
display - the text box
Then I've tried using this code:
[wnd setTitle:[display value]];
Unfortuanately it didn't work ...
The debugger said :
2010-05-22 XX:XX:08.577
HelloWorld[2536:a0f] -[NSTextField
value]: unrecognized selector sent to
instance 0x102e032a0
Does anyone know how to get it to work?
Not my forte, but try stringValue instead of value.
NSTextFiled does not have a method value - try stringValue.
See NSControl the superclass of NSTextField
I need to keep an NSPathControl updated with the currently selected path in an NSBrowser, but I'm having trouble figuring out a way of getting notifications when the path has changed from the NSBrowser. The ideal way to do this would just to be to observe the path key path in the NSBrowser, but that gives a KVO can only observe set<key> methods which return void message and no updates (setPath returns a bool success value).
I also tried observing the selectedCell key path, but I'm not getting notifications when the selection there is changed.
Is there some other really obvious way to do this that I'm missing?
Courtesy of Rob Keniger over at Cocoa Dev:
Have you looked at the SimpleBrowser
example in /Developer/Examples? It
shows how to get the current selection
when it is changed by the user,
basically by just setting up the
action of the NSBrowser.
That is indeed the way to do it. Just implement a method like - (void)browserClicked: in your controller and map it to the NSBrowser's action in interface builder with whatever you want to happen each time the selection changes inside that method, e.g.
- (void)browserClicked:(id)browser {
self.pathToSelectedCell = [browser path]; // NSPathControl is bound to pathToSelectedCell
}
I just checked in IB, and it looks like NSBrowser has a selection index paths binding (an array of NSIndexPath objects) that you could possibly monitor with KVO. It's strange but I don't see any mention of it in the docs, so you might need to do a little research to see if that's something you should or shouldn't use, even if it seems to work. If it does, in your KVO observation method you would find the browser's current path, and convert that to an NSURL the path control can use.
If that doesn't work there's also the delegate methods - (BOOL)browser:(NSBrowser *)sender selectRow:(NSInteger)row inColumn:(NSInteger)column and - (BOOL)browser:(NSBrowser *)sender selectCellWithString:(NSString *)title inColumn:(NSInteger)column.
As of 10.6, one can find out which items are selected, by using the delegate callback as follows:
- (NSIndexSet *)browser:(NSBrowser *)browser selectionIndexesForProposedSelection:(NSIndexSet *)proposedSelectionIndexes inColumn:(NSInteger)column
{
NSLog(#"New first item of the new selection is at index %#", [proposedSelectionIndexes firstIndex]);
// Do something with the selected index or indicies
return proposedSelectionIndexes; // Allow the selection to occur by not changing this
}