Re: Making a text cell in a table editable
Re: Making a text cell in a table editable
- Subject: Re: Making a text cell in a table editable
- From: "Vitaly Ovchinnikov" <email@hidden>
- Date: Thu, 10 Jul 2008 13:13:08 +0400
I though about sorting, need to try that you wrote. Thank you.
On Thu, Jul 10, 2008 at 12:08 PM, Abizer Nasir <email@hidden> wrote:
> Try this.
>
> Run your application and create a sort on one of the columns (by clicking in
> the header). Now add your new items. Regardless of your sorting, the new
> items will appear at the end of the table view.
>
> Now. Add the call to rearrangeObjects: and when you add the new item. It
> will appear in the correct sort order, depending on the default values set
> when creating the new object.
>
> PsuedoCode (blatantly ripped off from Hillegass 3e, P150.)
>
> MyObject *p = [[MyObject alloc] init];
> [arrayController addObject:p];
> [p release];
> // So far this is what you have done - created the object and added it to
> the array.
>
> // Now, resort your array depending on the way the user has sorted columns
> [arrayController rearrangeObjects];
>
> // Create an array based on the sorted array.
> NSArray *sortedArray = [arrayController arrangedObjects];
>
> // Find index of the object that you just added in this sorted array
> int row = [sortedArray indexOfObjectIdenticalTo:p];
>
> // Now we know the position of the item you just added, begin the edit.
> [grid editColumn:0 row:row withEvent:nil selected:YES];
>
>
> HTH
>
> Abizer.
>
>
> On 10 Jul 2008, at 07:46, Vitaly Ovchinnikov wrote:
>
>> I replaced my code with this one:
>>
>> MyObject *p = [[MyObject alloc] init];
>> [arrayController addObject:p];
>> [p release];
>> [grid editColumn:0 row:[grid selectedRow] withEvent:nil selected:YES];
>>
>> it works fine, NSTableView selects new row, -editColumn receives
>> correct row number and starts editing. So, the question is: why do I
>> need to call -rearrangeObjects? In what cases missing of this call
>> will lead to problems?
>>
>> On Thu, Jul 10, 2008 at 12:49 AM, I. Savant <email@hidden>
>> wrote:
>>>>
>>>> Same goes for -add: ... You'll need to force the array controller to
>>>> -rearrangeObjects before asking the tableView to reload. If you're
>>>> using Core Data, you'll probably also need to force a -fetch: before
>>>> calling -rearrangeObjects, though I don't know for sure.
>>>>
>>>> This forces the array controller to do its thing right then and
>>>> there. Of course short-circuiting the mechanism like that can cause
>>>> validation problems, so be careful ...
>>>
>>> Sorry! I'm not thinking straight ... you will need to directly use
>>> the -addObject: and -insertObject:atArrangedObjectIndex: methods
>>> rather than -insert: or -add: for the above to work. This takes affect
>>> immediately (but must still be rearranged via -rearrangeObjects).
>>>
>>> Also, you need to use the index of the newly-inserted object in the
>>> array controller's -arrangedObjects array, not its contents (so you
>>> get the correct row to edit in the table).
>>>
>>> --
>>> I.S.
>>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> 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:
>>
>> This email sent to email@hidden
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> 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:
>
> This email sent to email@hidden
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden