• 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
NSRuleEditor with Multiple Root Criteria Yields Empty Row
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSRuleEditor with Multiple Root Criteria Yields Empty Row


  • Subject: NSRuleEditor with Multiple Root Criteria Yields Empty Row
  • From: Jamie Phelps <email@hidden>
  • Date: Wed, 27 Aug 2008 08:16:34 -0500

Hi, all. I've been banging my head against this for some time now and I'm at a bit of a loss. I've searched the archives and haven't found much info on NSRuleEditor other than before Leopard was released and it was taboo because of NDA. Bear with me as I've done some experimentation that might help troubleshoot the problem if I weren't so cross-eyed from it already. :) I've read the documentation and NSRuleEditor.h more times than I care to admit.

The first method below is the initializer for my criterion class JPCriterion. The next three methods are NSRuleEditor's required delegate methods. When the criterion parameter of these is nil, it means to request a root criterion. I want to have three root criteria (It presents a drop-down menu.) but if I increase the number of children for the root, the row displays as shown in this screenshot: http://skitch.com/jrphelps/wcgu/nsruleeditor-troubles

In addition to tinkering with my app, I have also created a test project, which I have posted here: http://www.jamiephelps.com/RuleEditorTest.zip This is really simple. It returns a random number of criteria using rand()%7 and ensures that there is at least one root criterion by rand()%7+1. The display value is always the same. This exhibits the expected behavior when there is more than one root criterion. Since it uses NSRuleEditor, it's Leopard only. I'm also using GC just for convenience for demo purposes.

So, if you have any thoughts about what the difference is between my implementation that catches the janks for root criteria > 1 and the example one that exhibits the correct behavior, I'd greatly appreciate it.

Thanks a ton,
Jamie



-(id)initWithTreeDepth:(NSInteger)depth branch:(NSInteger)node{
if(self = [super init]){
[self setValue:[NSNumber numberWithInt:depth] forKey:@"treeDepth"];
[self setValue:[NSNumber numberWithInt:node] forKey:@"index"];
children = [[NSMutableArray alloc] init];
switch(depth){
case 1:
[children addObject:[[[JPRegexBuilderCriterion alloc] initWithTreeDepth:2 branch:0]] autorelease];
[children addObject:[[[JPRegexBuilderCriterion alloc] initWithTreeDepth:2 branch:1]] autorelease];
switch(node){
case 0:
[self setValue:@"Foo" forKey:@"displayValue"];
break;
case 1:
[self setValue:@"Bar" forKey:@"displayValue"];
break;
case 2:
[self setValue:@"Bat" forKey:@"displayValue"];
break;
}
break;
...etc.



- (id)ruleEditor:(NSRuleEditor *)editor
child:(NSInteger)index
forCriterion:(id)criterion
withRowType:(NSRuleEditorRowType)rowType
{
if(criterion == nil){
JPCriterion *c = [[[JPCriterion alloc] initWithTreeDepth:1 branch:index] autorelease];
return c;
}
return [[criterion children] objectAtIndex:index];
}


- (id)ruleEditor:(NSRuleEditor *)editor
displayValueForCriterion:(id)criterion
           inRow:(NSInteger)row
{
    return [criterion valueForKey:@"displayValue"];
}

- (NSInteger)ruleEditor:(NSRuleEditor *)editor
numberOfChildrenForCriterion:(id)criterion
            withRowType:(NSRuleEditorRowType)rowType
{
    // Anything greater than 1 causes the rows
    // to display empty with + and - buttons.
    if(criterion == nil) return 1;

    return [[criterion children] count];
}
@end
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: how to release CFData
  • Next by Date: Re: applicationDockMenu: not called
  • Previous by thread: Re: Design Question: Bindings & Custom Views
  • Next by thread: Re: 2 NSRuleEditor questions?
  • Index(es):
    • Date
    • Thread