Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 587797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:15:02+00:00 2026-05-13T15:15:02+00:00

In Aaron Hillegass’ Cocoa Programming for Mac OS X , Chapter 9, the section

  • 0

In Aaron Hillegass’ Cocoa Programming for Mac OS X, Chapter 9, the section called “Begin Editing on Insert”, he explains how to do exactly that. The thing that confused me though, was that he did a bunch of other stuff. Here’s the full code listing:

- (IBAction)createEmployee:(id)sender
{
NSWindow *w = [tableView window];

// Try to end any editing that is taking place
BOOL editingEnded = [w makeFirstResponder:w];
if (!editingEnded) {
    NSLog(@"Unable to end editing");
    return;
}
NSUndoManager *undo = [self undoManager];

// Has an edit occurred already in this event?
if ([undo groupingLevel]) {
    // Close the last group
    [undo endUndoGrouping];
    // Open a new group
    [undo beginUndoGrouping];
}
// Create the object
Person *p = [employeeController newObject];

// Add it to the content array of 'employeeController'
[employeeController addObject:p];
[p release];
// Re-sort (in case the user has sorted a column)
[employeeController rearrangeObjects];

// Get the sorted array
NSArray *a = [employeeController arrangedObjects];

// Find the object just added
int row = [a indexOfObjectIdenticalTo:p];
NSLog(@"starting edit of %@ in row %d", p, row);

// Begin the edit in the first column
[tableView editColumn:0
                  row:row
            withEvent:nil
               select:YES];
}

I have two questions regarding this:

1) How do you know you’re supposed to do all that stuff? Is there a ‘checklist’ or something in Apple’s doc? Experience?

2) Doesn’t this defeat the whole purpose of an array controller if you’re having to still rewrite all the methods on your own?

EDIT: I’m mainly wondering how he knew to put these lines in: (since everything else is pretty basic and obvious)

NSWindow *w = [tableView window];

// Try to end any editing that is taking place
BOOL editingEnded = [w makeFirstResponder:w];
if (!editingEnded) {
    NSLog(@"Unable to end editing");
    return;
}
NSUndoManager *undo = [self undoManager];

// Has an edit occurred already in this event?
if ([undo groupingLevel]) {
    // Close the last group
    [undo endUndoGrouping];
    // Open a new group
    [undo beginUndoGrouping];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:15:03+00:00Added an answer on May 13, 2026 at 3:15 pm

    1) How do you know you’re supposed to do all that stuff? Is there a ‘checklist’ or something in Apple’s doc? Experience?

    You’re right, that code wouldn’t occur to most people doing an initial implementation. (I guess that’s why it’s in the book. You get to benefit from Aaron’s experience).

    That code would have come as the result of one or more bug reports. In other words, you wouldn’t come up with that code initially, but you would eventually.

    Try it for yourself. Remove that code then see if you can spot the problems in the running application. Solving those problems requires a combination of SDK knowledge and debugging skill. Both grow with experience.

    2) Doesn’t this defeat the whole purpose of an array controller if you’re having to still rewrite all the methods on your own?

    One could argue that the ability to modify the tableview’s behavior like that is the whole point of the array controller (as an element of your application’s design).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 308k
  • Answers 308k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You have to understand that many screen reader users don't… May 13, 2026 at 9:46 pm
  • Editorial Team
    Editorial Team added an answer You need a simple state machine. This is a way… May 13, 2026 at 9:46 pm
  • Editorial Team
    Editorial Team added an answer // Get properties list objc_property_t* class_copyPropertyList(Class cls, unsigned int *outCount);… May 13, 2026 at 9:46 pm

Related Questions

I'm learning objective-c, working through Aaron Hillegass' book Cocoa Programming for Mac OS X
I am in the process of learning Objective-C for Mac/iPhone development and decided to
Back in the day of C/C++, the part of the language that really hung
I'm rather confused about properties and instance variables in Objective-C. I'm about half-way through
I would love to learn to program in pure UNIX with C kernell calls

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.