Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

medasmx

macrumors member
Original poster
Nov 9, 2008
89
0
I have been messing around with custom nscells, to put them in a matrix. That was my last post. However, I don't think I have a great grasp on nsmatrix first. So I tried to write a program that takes a nspopupbutton, and puts a string "jimmy" into one of four boxes in a nsmatrix. When I compile it it runs but nothing happens. Selecting different indices on the popupbutton doesn't do anything. When you terminate the compiler, you get the following message: "[NSTextField setControlView:]: unrecognized selector sent". Any help would be appreciated. Below is the code. Thanks. Adam

Code:
#import <Cocoa/Cocoa.h>


@interface AppController : NSObject {
IBOutlet NSMatrix*myMatrix;
NSString*myString;
NSTextField*myTextField;
}
-(IBAction)myButton:(id)sender;

@end


#import "AppController.h"

@implementation AppController

-(IBAction)myButton:(id)sender
{
[myMatrix setCellClass:[NSTextField class]];
myTextField=[[NSTextField alloc]init];
[myTextField setStringValue:@"jimmy"];
myString=[(NSPopUpButton*)sender titleOfSelectedItem];
if([myString isEqualToString:@"one"])
	[myMatrix putCell:myTextField atRow:0 column:0];
if([myString isEqualToString:@"two"])
	[myMatrix putCell:myTextField atRow:0 column:1];
if([myString isEqualToString:@"three"])
	[myMatrix putCell:myTextField atRow:1 column:0];
if([myString isEqualToString:@"one"])
	[myMatrix putCell:myTextField atRow:1 column:1];
}

@end
 
I partially solved the thread that I posted. When I used setPrototype: and set it to a nstextfieldcell, it worked. The only problem I am having now is that one text field is always highlighted and you can't put the string in that field. I tried changing the mode of the matrix but it didn't do anything. Below is the new code. Adam

Code:
#import "AppController.h"

@implementation AppController

-(void)awakeFromNib
{
otherTextFieldCell=[[NSTextFieldCell alloc]init];
[otherTextFieldCell setPlaceholderString:@""];
[myMatrix setMode:NSListModeMatrix];
[myMatrix setPrototype:otherTextFieldCell];
}

-(IBAction)myButton:(id)sender
{
myTextFieldCell=[[NSTextFieldCell alloc]init];
[myTextFieldCell setStringValue:@"jimmy"];
myString=[(NSPopUpButton*)sender titleOfSelectedItem];
if([myString isEqualToString:@"one"])
	[myMatrix putCell:myTextFieldCell atRow:0 column:0];
if([myString isEqualToString:@"two"])
	[myMatrix putCell:myTextFieldCell atRow:0 column:1];
if([myString isEqualToString:@"three"])
	[myMatrix putCell:myTextFieldCell atRow:1 column:0];
if([myString isEqualToString:@"four"])
	[myMatrix putCell:myTextFieldCell atRow:1 column:1];
}

@end
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.