FROM : William Squires
DATE : Sun Jun 22 18:46:41 2008
Okay, thanks. It seems to work if I just typecast it to NSString *,
since the values are coming from an NSTextField as [textField
stringValue] in my AppController.m when the action is triggered from
the "Add" buttton.
On Jun 22, 2008, at 11:13 AM, Jeff LaMarche wrote:
>
> On Jun 22, 2008, at 12:02 PM, William Squires wrote:
>
>> okay, looking up tableView:setObjectValue:forTableColumn:row shows
>> that setObjectValue: takes an (id), but what is it really? An
>> NSString pointer? I want to get an NSString that represents the
>> new value the user typed in for the selected (and edited) cell in
>> the NSTableView. Can I safely typecast this to (NSString *)? In
>> which case, maybe the docs should say that this is an (NSString *)
>> instead of (id)?
>
> The documentation is correct. The Table View Programming Guide states:
>
> The NSTableView object treats objects provided by its data source
> as values to be displayed in NSCell objects. If these objects
> aren’t of common value classes—such as NSString, NSNumber, and so on
> —you may need to create a custom NSFormatter object to display
> them. For more information, see Data Formatting Programming Guide
> for Cocoa.
>
> In other words, it's not always going to be an NSString *. Whatever
> the object is, it will be converted to a string for display, but
> the table view is actually capable of holding different types of
> data and doesn't change the type that it's holding, so you can't
> assume that the object it holds is a string. Now, if you are giving
> the table strings, then by all means, cast the object to an
> NSString. If you're not sure what the type of object you're getting
> back is, you can find out in the debugger console by typing
>
> po [returnedValue class]
>
> or adding an NSLog statement to your code like
>
> NSLog(@"returned value class: %@", [returnedValue class]);
>
> HTH
>
DATE : Sun Jun 22 18:46:41 2008
Okay, thanks. It seems to work if I just typecast it to NSString *,
since the values are coming from an NSTextField as [textField
stringValue] in my AppController.m when the action is triggered from
the "Add" buttton.
On Jun 22, 2008, at 11:13 AM, Jeff LaMarche wrote:
>
> On Jun 22, 2008, at 12:02 PM, William Squires wrote:
>
>> okay, looking up tableView:setObjectValue:forTableColumn:row shows
>> that setObjectValue: takes an (id), but what is it really? An
>> NSString pointer? I want to get an NSString that represents the
>> new value the user typed in for the selected (and edited) cell in
>> the NSTableView. Can I safely typecast this to (NSString *)? In
>> which case, maybe the docs should say that this is an (NSString *)
>> instead of (id)?
>
> The documentation is correct. The Table View Programming Guide states:
>
> The NSTableView object treats objects provided by its data source
> as values to be displayed in NSCell objects. If these objects
> aren’t of common value classes—such as NSString, NSNumber, and so on
> —you may need to create a custom NSFormatter object to display
> them. For more information, see Data Formatting Programming Guide
> for Cocoa.
>
> In other words, it's not always going to be an NSString *. Whatever
> the object is, it will be converted to a string for display, but
> the table view is actually capable of holding different types of
> data and doesn't change the type that it's holding, so you can't
> assume that the object it holds is a string. Now, if you are giving
> the table strings, then by all means, cast the object to an
> NSString. If you're not sure what the type of object you're getting
> back is, you can find out in the debugger console by typing
>
> po [returnedValue class]
>
> or adding an NSLog statement to your code like
>
> NSLog(@"returned value class: %@", [returnedValue class]);
>
> HTH
>
| Related mails | Author | Date |
|---|---|---|
| William Squires | Jun 22, 18:02 | |
| Jeff LaMarche | Jun 22, 18:13 | |
| Daniel Richman | Jun 22, 18:14 | |
| Jens Alfke | Jun 22, 18:22 | |
| William Squires | Jun 22, 18:46 | |
| Quincey Morris | Jun 22, 21:44 |






Cocoa mail archive

