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
Related
I apologize if the title is somewhat misleading, I didn't know how to describe the problem. So I came across an online tutorial today and I encountered a line of code that got me asking a few questions.
For example this line of code
UIImageView *recipeImageView = (UIImageView *)[cell viewWithTag:100]; <--- What is this part?
What is it doing here? Does it return an instance of UIImageView(or converting it maybe)? I didn't know you could doing something like this.
Many thanks.
[cell viewWithTag:100] is a method call (message send). The pointer cell is the object pointer, and viewWithTag is the method of that object that is being called, passing as a parameter the numeric value 100.
The method call returns a UIView pointer which is cast into an UIImageView pointer (presumably because the programmer knows that's the correct type) before assigning to recipeImageView.
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))
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 want to blank a NSTextField that has a IB Number Formatter associated with it, the formatter restricts it to positive integers.
It didn't occur to me before I did it but predictably setString:#"" returns
-[NSTextField setString:]: unrecognized selector
Is this possible and what method would I use to do it?
Thanks!
Graham
You're looking for setStringValue: