Description: Row parameters in table. It is used in data source for creating an arras with rows containing expanders.
@interface GridRow : NSObject{ NSMutableArray *children; // Array of child rows } @property (nonatomic, readonly) NSString *title; // Row header @property (nonatomic, readonly) NSArray *values; // Row value @property (nonatomic, readonly) GridRow *parent; // Parent row @property (nonatomic) BOOL isExpanded; // Indicates whether row is expanded // Initializes row by header and data - (id)initWithHeader:(NSString *)header andData:(NSArray *)data; // Initializes row by header, data and parent - (id)initWithHeader:(NSString *)header andData:(NSArray *)data andParent:(GridRow *)parentRow; // Returns child row by its index - (GridRow *)childAtIndex:(NSInteger)index; // Returns the number of child rows - (NSInteger)childrenCount; // Adds child row - (void)addChild:(GridRow *)row; // Returns row level in hierarchy of all table rows - (NSInteger)level; @end
#import "GridRow.h" @implementation GridRow @synthesize title, values, parent, isExpanded; // Initializes row by header and data - (id)initWithHeader:(NSString *)header andData:(NSArray *)data{ if ((self = [super init])) { title = [[NSString stringWithString:header] retain]; values = [[NSArray arrayWithArray:data] retain]; parent = nil; isExpanded = NO; return self; } else return nil; } // Initializes row by header, data and parent - (id)initWithHeader:(NSString *)header andData:(NSArray *)data andParent:(GridRow *)parentRow { if ((self = [self initWithHeader:header andData:data])) { parent = parentRow; [parent addChild:self]; return self; } else return nil; } // Returns child row by its index - (GridRow *)childAtIndex:(NSInteger)index { if (children && index < [children count ]) return [children objectAtIndex:index]; else return nil; } // Returns the number of child rows - (NSInteger)childrenCount { return [children count]; } // Adds child row - (void)addChild:(GridRow *)row { if (!children) children = [[NSMutableArray new] retain]; [children addObject:row]; } // Returns row level in hierarchy of all table rows - (NSInteger)level { if (parent) return [parent level] + 1; else return 0; } // Determines whether table row is expanded - (void)setIsExpanded:(BOOL)expanded { if ([children count]) isExpanded = expanded; else isExpanded = NO; } - (void)dealloc { [title release]; [values release]; [children release]; [super dealloc]; } @end
See also: