On May 8, 2012, at 8:48 PM, Antonio Nunes <devli...@sintraworks.com> wrote:

> On 8 May 2012, at 23:10, Corbin Dunn wrote:
> 
>> 
>> On May 8, 2012, at 1:35 PM, Antonio Nunes <devli...@sintraworks.com> wrote:
>> 
>>> On 8 May 2012, at 21:46, Andy Lee wrote:
>>> 
>>>> Bizarre indeed. Out of curiosity, are you using ARC? Maybe the compiler is 
>>>> confusedly zeroing a non-weak pointer. I'm *really* grasping at straws, 
>>>> though.
>>> 
>>> No ARC. No garbage collection either.
>>> 
>>>> Are there any bindings on the text field? Again, I don't see why it would 
>>>> matter; just wondering.
>>> 
>>> No bindings.
>>> 
>>>>> I don't release @"" anywhere, so that is indeed very, very unlikely. 
>>>>> Also, if I avoid the exception and assign @"" to a text field a bit later 
>>>>> on in another piece of code, it works just fine.
>>>> 
>>>> The same text field (toolbarPageNumberTextField), or a different one?
>>> 
>>> Another text field. I'm seeing different behaviour though between letting 
>>> the code run naturally to the empty string assignment and manually moving 
>>> the PC to the line in question. I'll take another look at it after a good 
>>> night's sleep...
>> 
>> You may have a formatter on the cell, and it is returning nil.
>> 
>> Also, you are mixing what you are using the text field for. In some cases 
>> you are treating it like an integer, and in others a string. I don't 
>> recommend using integerValue in your case; instead, convert that integer to 
>> a string (and vice-versa when you read the value via 
>> self.toolbarPageNumberTextField.integerValue). If you fix those things your 
>> problem will probably go away.
> 
> Thanks Corbin,
> 
> Indeed, there is a number formatter on the cell

Okay-- then that is the problem; the formatter is failing to format "" to be a 
number, and giving 'nil' back when you call setStringValue. 

> , so probably that is causing the issue then. To make it possible to have an 
> empty text field when there are no pages in the document I changed the symbol 
> for 0:
>       [self.toolbarPageNumberTextField.formatter setZeroSymbol:@""]; (I did 
> not know this is possible, until a few minutes ago.)

> 
> Then changed all instances of:
>                               self.toolbarPageNumberTextField.stringValue = 
> @"";
> 
> to
>                               self.toolbarPageNumberTextField.stringValue = 
> @"0";
> 

Did that fix the problem? 


> Following your recommendation I also changed
>                                       
> self.toolbarPageNumberTextField.integerValue = 
> self.pageListController.selectionIndex + 1;
> to
>                                       
> self.toolbarPageNumberTextField.stringValue = [NSString 
> stringWithFormat:@"%d", self.pageListController.selectionIndex + 1];
> 
> Why do you recommend against using integerValue? For me it would make more 
> sense to always use integerValue, especially now that I can set the value to 
> 0 to show an empty text field, since we're conceptually representing numbers 
> here, not strings.

Well, it is just more consistent if you treat it all the same. Plus, when you 
read the integerValue, what NSCell doe is creates an NSScanner and scans the 
string (in the cell) for an integer and returns that value. This creates a 
scanner with your current locale...which may or may not be what you want (it 
probably is). When you call setIntegerValue it sets the objectValue of the cell 
to be an NSNumber. It really isn't an issue, but it just flip-flops the value 
type from a string to an integer back and forth. 

corbin


> 
> -António
> 
> 
> 
> -----------------------------------------------------------
> Don't believe everything you think
> -----------------------------------------------------------
> 
> 
> 
> 


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to