简体   繁体   中英

How difficult is to implement a custom NSCell with a NSStepper and a label ?

How difficult is to implement a custom NSCell with a NSStepper and a label displaying the value incremented/decremented by the stepper?

I can't add subviews to it, so how can I add such subcomponents?

thanks

Yes it is possible that you can take NSStepperCell in your NSTableView. But for this value to be appear in your NSTableView, You have to take two NSTableColumn in one column drag and drop NSStepperCell and in another by default it will be textcell so let it be. Now bind both your column to array controller with model keypath. In NSStepperCell model key path should be float value and other will be sinple string value. Once you done this then write one action method and bind to the NSStepperCell. Below is the action method written to appear the value.

-(IBAction)doIncrement:(id)sender
{
    step+=1.0; ///This step is the float value of NSStepperCell and binded with arrayController
NSNumber *num=[NSNumber numberWithFloat:step];
    NSMutableDictionary *dict=[NSMutableDictionary dictionary];
    for(dict in [arrayController arrangedObjects])
    {
        [dict setObject:num forKey:@"displayStepperValue"];  //@"displayStepperValue" this is another column textcell which will print steppercell value when you click on the arrows of NSStepperCell.
    }
    [arrayController rearrangeObjects]; //here refershing the arraycontroller

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM