• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
A couple of NSTable questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A couple of NSTable questions


  • Subject: A couple of NSTable questions
  • From: Mike Brinkman <email@hidden>
  • Date: Wed, 30 Jul 2003 10:17:25 -0400

I have just finished reading chapter 9 of "Learning Cocoa With Objective C
(2nd Ed.)". After I finish every chapter, I try to write a similar app, but
with more functionality, both to challenge myself and enforce what I've
already learned.

I'm making up a mini-program which simply lets you enter a to do item (an
NSString) and a due date (NSCalendarDate) into and NSTextFields, and then
loads the items into an NSTableView.

They're called:
NSString *toDo;
NSCalendarDate *dueDate;

The table is just called "table". Everything works fine, including sorting
the columns. I did run across one problem with the sorting though. I was
changing options for my NSTableView, and deselected "Allows Reordering"
because I don't want for the table columns to be switched around. The
problem is that this prevents the contents of the table from being sorted.
Is there a way to allow the rows to be reordered while still preventing the
columns from being rearranged?

The sorting method looks like this:

- (void)tableView:(NSTableView *)tableView
didClickTableColumn:(NSTableColumn *)tableColumn
{
NSString *identifier = [tableColumn identifier];

if ([identifier isEqualToString:@"toDo"]) {
[toDoList sortUsingSelector:@selector(compareToDo:)];
} else {
[toDoList sortUsingSelector:@selector(compareDueDate:)];
}

[table reloadData];
}

*********

Next objective I wanted to do was to make any appointments ending within 7
days to show up in red. I know that if I was just going to draw a string in
a view, all I would do is something like this:

NSMutableDictionary *attribs = [NSMutableDictionary dictionary];
[attribs setObject:[NSColor redColor]
forKey:NSForegroundColorAttributeName];

[myString drawAtPoint:NSMakePoint(x, y)
withAttributes:attribs];

I also know that if I wanted to check the interval between today's date and
the due date, I would simply write:

[dueDate years:NULL months:NULL days:&days hours:NULL minutes:NULL
seconds:NULL sinceDate:[NSCalendarDate calendarDate]]

Then I could compare the result in an if statement and set the color
attribute. I can't figure out how to do this when loading the data into the
NSTableView though. Where would I put the if statement?

Thanks for any help!
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: A couple of NSTable questions
      • From: Stéphane Sudre <email@hidden>
  • Prev by Date: Stef, Dienstag, Prachi many thanks!!--for scanf answer (nm)
  • Next by Date: Re: Floating palette close behavior
  • Previous by thread: Stef, Dienstag, Prachi many thanks!!--for scanf answer (nm)
  • Next by thread: Re: A couple of NSTable questions
  • Index(es):
    • Date
    • Thread