• 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
Re: rows of pop up button cells with unique menus
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: rows of pop up button cells with unique menus


  • Subject: Re: rows of pop up button cells with unique menus
  • From: "Matt Mashyna" <email@hidden>
  • Date: Wed, 20 Sep 2006 16:16:27 -0400 (EDT)
  • Importance: Normal

I do the popup cell in a table a little differently than your example. I don't
link the popup button cell to a menu in IB. I keep an array on NSNumbers --
one item for each row -- and use the delegate methods to get and set them like
this:

	ticketPopup = [[[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown: NO]
retain]; // my document class holds ticketPopup
	[ticketPopup setEditable: YES];
	[ticketPopup setControlSize: NSSmallControlSize];
	[ticketPopup setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
	[[ticketFieldTable tableColumnWithIdentifier: @"option"] setDataCell:
ticketPopup]; // option is the identifier in IB

// here I am putting the menu items in manually
	[ticketPopup addItemWithTitle:@"Hidden"];
	[[ticketPopup itemWithTitle:@"Hidden"] setTag: 1];
	[ticketPopup addItemWithTitle:@"Optional"];
	[[ticketPopup itemWithTitle:@"Optional"] setTag: 2];
	[ticketPopup addItemWithTitle:@"Required"];
	[[ticketPopup itemWithTitle:@"Required"] setTag: 3];


Here are my delegate methods. All "Option" menu cells take NSNumbers.

///////////////// DATA SOURCE METHODS //////////////////
- (id)  tableView:(NSTableView *) aTableView
		objectValueForTableColumn:(NSTableColumn *) aTableColumn
		row:(int) rowIndex
{
	NSString*	colName = [aTableColumn identifier];
	if([[aTableColumn identifier] isEqual:@"xmltag"])
	{
		return [tags objectAtIndex:rowIndex];
	}
	else if([[aTableColumn identifier] isEqual:@"prompt"])
	{
		return [prompts objectAtIndex:rowIndex];
	}
	else if([[aTableColumn identifier] isEqual:@"defaultvalue"])
	{
		return [defaults objectAtIndex:rowIndex];
	}
	else if([[aTableColumn identifier] isEqual:@"option"])
	{
		return [options objectAtIndex:rowIndex];
	}
	else
		return nil;
} // objectValueForTableColumn

- (void)tableView:(NSTableView *) aTableView
		setObjectValue:(id)anObject forTableColumn:(NSTableColumn *) aTableColumn
		row:(int)rowIndex
{
	if([[aTableColumn identifier] isEqualToString:@"xmltag"])
	{
		[tags replaceObjectAtIndex:rowIndex withObject:anObject];
	}
	if([[aTableColumn identifier] isEqualToString:@"prompt"])
	{
		[prompts replaceObjectAtIndex:rowIndex withObject:anObject];
	}
	if([[aTableColumn identifier] isEqualToString:@"defaultvalue"])
	{
		[defaults replaceObjectAtIndex:rowIndex withObject:anObject];
	}
	if([[aTableColumn identifier] isEqualToString:@"option"])
	{
		[options replaceObjectAtIndex:rowIndex withObject:anObject];
	}

} // setObjectValue

> I have looked through the archives and searched Google for
> information on using NSPopUpButtonCells in NSTableViews.
>
> In particular, I have followed http://www.corbinstreehouse.com/blog/?
> p=22.
>
> Now, my application, I have a table with two columns.  One column
> shows a user's name, and the other an NSPopUpButton cell that I want
> to hold a list of the user's email addresses that I have extracted
> from an X.509 certificate.  (There would typically be only one or two
> email addresses listed.)
>
> When the pop up button is clicked, the menu pops up, and is populated
> with the correct information in the menuNeedsUpdate: delegate
> method.  The problem is that I can't figure out how to get the pop up
> button cell in the relevant row to display the selected item after
> the button pops down.
>
> I would think that I need each pop up button cell to have its very
> own menu, but I can't quite see how to arrange this.
>
> I feel like I only vaguely understand how the NSTableView uses
> prototype cells to draw all the rows, so maybe this lack of
> background is confusing me.  If the same cell is used to draw all the
> rows, how can I have a separate menu for each cell?
>
> If anyone could point me at some documentation or examples, I would
> certainly appreciate it.  I know this sort of question has been asked
> in the past, so I apologize if I have overlooked a previously-given
> answer.
>
>
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
>


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >rows of pop up button cells with unique menus (From: "R. Matthew Emerson" <email@hidden>)

  • Prev by Date: Re: Trying to remove default dock menu items.
  • Next by Date: Does addition of new entity to data model require migration?
  • Previous by thread: Re: rows of pop up button cells with unique menus
  • Next by thread: Out of Office
  • Index(es):
    • Date
    • Thread