Set a NSTextField to blank with a NumberFormatter - objective-c

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:

Related

How do I get the current font/font size at cursor in NSTextView?

Clarification: First, cursor = the insertion point cursor, not the mouse cursor.
Ok, I would like to return the font / font size / font color wherever the cursor is in the NSTextView. I tried using attribute:atIndex:effectiveRange:, but I failed because I got my variables all mixed up. I think it is what I need. Some example code would just be appreciated, returning the font. I think it will work the same for font size/color, I'll just have to substitute NSFontAttributeName for something else, right? Thanks in advance!
NSFont *font = [textView.textStorage attribute:NSFontAttributeName atIndex:textView.selectedRange.location effectiveRange:nil];
Should work for all getting the name.
What have you tried?
NSTextView has a method selectedRanges which returns the current selection(s) - just one of zero-length if there is just an insertion point.
NSTextView also has a property textStorage which returns back the instance of NSTextStorage which holds the text. An NSTextStorage inherits from NSMutableAttributedString, which inherits from NSAttributedString, and that has methods to obtain the attributes of the text.
Combined those two and you have your answer.
HTH

Pointer to an object before sending message

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.

NSTableView sort problem(with KVC)

I had a weird problem on NSTableView sort.
I created a simple app with a NSTableView which
has 4 columns. Then I used KVC to bind it to a
Array controller.
Then I added some data to the NSMutableArray.
Bulid&&Run the app and I can see the data inside
the table and by clicking the header the data can
be sorted correctlly.
Everything works fine up till now.
Then I tried to add the "caseInsensitiveCompare" to
each columns. So I opened the IB, set the sort key and
selector ("caseInsensitiveCompare:") to each columns.
Then Bulid&&Run the app, but when I click the header to
sort, I got the error message:
-[NSCFNumber caseInsensitiveCompare:]: unrecognized selector sent to instance 0x1006254f0
-[NSCFNumber caseInsensitiveCompare:]: unrecognized selector sent to instance 0x1006254f0
......
Then I tried to delete all the content in the sort key and
selector of each columns. And the app became OK again.
What seems to be the problem? I am really confused...
ps:
If I use compare: instead of caseInsensitiveCompare:, everything works fine again...
One of the values (such as a property or key) of your objects in your NSMutableArray is of class NSNumber. Since this class deals with numbers, it doesn't respond to the caseInsensitiveCompare: selector. This selector is meaningful to NSString.
The column on your table view that is displaying number values should keep using compare: for sorting the values.

Frustrating problem with NSTextView

I want to print out the Text contents of a NSTextView using the NSLog function in Objective-C. The code I have so far is:
NSString *s=[updateSource textStorage];
NSLog(s);
All I get is the error:
[NSConcreteTextStorage getCharacters:range:]: selector not recognized [self = 0x43f4b0]
Use [updateSource string] instead. [updateSource textStorage] is not an NSString, but rather an NSTextStorage.
It's not the cause of your problem, but you should be using NSLog(#"%#",s); to log your string. The first argument of NSLog should always be a format string, and not the value you're trying to log.
(if you don't, your app will likely crash if the value contains percent characters)

Change window title to the one in text box in Objective-C?

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