हैलो मैं एक एनएसपीओपी व्यू के अंदर एक एनएसपीओपअप बटन का उपयोग करने की कोशिश कर रहा हूं। असल में जब आप पॉप अप में कोई आइटम चुनते हैं तो मैं इसे तालिका दृश्य कॉलम/पंक्ति में प्रदर्शित करना चाहता हूं। जब पॉपअप सेल में कोई आइटम दबाया जाता है, तो मैं इसे "tableView: setObject: forTableColumn: row" का उपयोग करके डेटा स्रोत के अंदर संग्रहीत करता हूं, फिर जब तालिका डेटा अनुरोध करती है तो मैं पुनर्प्राप्त करता हूं और पॉपअप सेल की स्थिति को "tableView: objectValueForTableColumn में सेट करता हूं: पंक्ति: "। कृपया मेरा कोड संलग्न करें। मैं अभी पूरी तरह से अटक गया हूँ। मुझे उम्मीद है कि कोई इसका एहसास कर सकता है। अग्रिम धन्यवाद।एनएसपीओपअपब्यूटनसेल का उपयोग एनएसटीबल व्यू
इस नियंत्रक के अंदर है:
//Create the table columns
NSTableColumn *nameColumn = [[NSTableColumn alloc] initWithIdentifier:LXDetailItemName];
NSTableColumn *dataTypeColumn = [[NSTableColumn alloc] initWithIdentifier:LXDetailItemDataType];
NSTableColumn *deviceColumn = [[NSTableColumn alloc] initWithIdentifier:LXDetailItemDevice];
//Data type column drop down
NSPopUpButtonCell *dataTypeDropDownCell = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:YES];
[dataTypeDropDownCell setBordered:NO];
[dataTypeDropDownCell setEditable:YES];
NSArray *dataTypeNames = [NSArray arrayWithObjects:@"NULL", @"String", @"Money", @"Date", @"Int", nil];
[dataTypeDropDownCell addItemsWithTitles:dataTypeNames];
[dataTypeColumn setDataCell:dataTypeDropDownCell];
//Add the columns to the table
[tableView addTableColumn:nameColumn];
[tableView addTableColumn:dataTypeColumn];
[tableView addTableColumn:deviceColumn];
enter code here
यह डेटा स्रोत/प्रतिनिधि वर्ग के अंदर है।
enter code here
@implementation LXTestDataSource
- (id)init
{
self = [super init];
if (self)
{
tableContents = [[NSMutableArray alloc] init];
//Setup test data
NSMutableArray *keys = [NSMutableArray arrayWithObjects:LXDetailItemName, LXDetailItemDataType, LXDetailItemDevice, nil];
NSMutableArray *objects = [NSMutableArray arrayWithObjects:@"one", @"NULL", @"NULL", nil];
for (int i = 0; i < 4; i++)
{
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithObjects:objects forKeys:keys];
[tableContents addObject:dictionary];
[dictionary release];
}
}
return self;
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
{
return [tableContents count];
}
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
if ([[aTableColumn identifier] isEqualToString:LXDetailItemDataType])
{
NSMutableDictionary *rowDictionary = [tableContents objectAtIndex:rowIndex];
NSString *title = [rowDictionary objectForKey:LXDetailItemDataType];
NSLog(@"objectValueForTableColumn: %@", title); //DEBUG
return [NSNumber numberWithInt:[[aTableColumn dataCell] indexOfItemWithTitle:title]];
}
else if ([[aTableColumn identifier] isEqualToString:LXDetailItemDevice])
{
NSMutableDictionary *rowDictionary = [tableContents objectAtIndex:rowIndex];
NSString *title = [rowDictionary objectForKey:LXDetailItemDevice];
NSLog(@"objectValueForTableColumn: %@", title); //DEBUG
return [NSNumber numberWithInt:[[aTableColumn dataCell] indexOfItemWithTitle:title]];
}
else
{
NSMutableDictionary *rowDictionary = [tableContents objectAtIndex:rowIndex];
return [rowDictionary objectForKey:[aTableColumn identifier]];
}
}
- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
if ([[aTableColumn identifier] isEqualToString:LXDetailItemDataType])
{
NSMenuItem *menuItem = [[aTableColumn dataCell] itemAtIndex:[anObject integerValue]];
NSMutableDictionary *rowDictionary = [tableContents objectAtIndex:rowIndex];
NSLog(@"%@", [menuItem title]); //DEBUG
//Update the object value at the column index
[rowDictionary setObject:[menuItem title] forKey:LXDetailItemDataType];
}
else if ([[aTableColumn identifier] isEqualToString:LXDetailItemDevice])
{
NSMenuItem *menuItem = [[aTableColumn dataCell] itemAtIndex:[anObject integerValue]];
NSMutableDictionary *rowDictionary = [tableContents objectAtIndex:rowIndex];
NSLog(@"%@", [menuItem title]); //DEBUG
//Update the object value at the column index
[rowDictionary setObject:[menuItem title] forKey:LXDetailItemDevice];
}
else
{
//Get the row
NSMutableDictionary *rowDictionary = [tableContents objectAtIndex:rowIndex];
//Update the object value at the column index
[rowDictionary setObject:anObject forKey:[aTableColumn identifier]];
}
}
@end
// सेटअप परीक्षण डाटा \ N NSDictionary * शब्दकोश = @ {LXDetailItemName: @ "एक", LXDetailItemDataType: @ "शून्य" LXDetailItemDevice: @ "शून्य"}; \ n (आई इंट = 0; मैं <4; i ++) {\ n [tableContents addObject: dictionary]; \ n } \ n – geowar