Permalink
Browse files

Adds constructor with a dictionary, issue #84

  • Loading branch information...
1 parent fe931b6 commit 329c50c2c63d064b310136f6b7ea2647d96fb560 @escoz escoz committed Mar 26, 2012
@@ -24,6 +24,8 @@
@property(nonatomic, assign, readwrite) NSInteger selected;
@property(nonatomic, retain) NSArray *values;
+- (QRadioElement *)initWithDict:(NSDictionary *)valuesDictionary selected:(int)selected title:(NSString *)title;
+
- (void)setSelectedValue:(NSObject *)aSelected;
- (QRadioElement *)initWithItems:(NSArray *)stringArray selected:(NSInteger)selected;
@@ -48,6 +48,16 @@ - (QRadioElement *)initWithItems:(NSArray *)stringArray selected:(NSInteger)sele
return self;
}
+
+- (QRadioElement *)initWithDict:(NSDictionary *)valuesDictionary selected:(int)selected title:(NSString *)title {
+ self = [self initWithItems:valuesDictionary.allKeys selected:(NSUInteger) selected];
+ _values = valuesDictionary.allValues;
+ self.title = title;
+ return self;
+}
+
+
+
- (QRadioElement *)initWithItems:(NSArray *)stringArray selected:(NSInteger)selected title:(NSString *)title {
self = [super init];
if (self!=nil){
@@ -30,4 +30,5 @@
- (QRadioSection *)initWithItems:(NSArray *)stringArray selected:(NSUInteger)selected title:(NSString *)title;
+- (QSection *)initWithDict:(id)valuesDictionary selected:(int)selected title:(NSString *)title;
@end
@@ -21,7 +21,6 @@ @implementation QRadioSection
@synthesize selected = _selected;
-
- (void)createElements {
for (NSUInteger i=0; i< [_items count]; i++){
@@ -254,6 +254,8 @@ + (QElement *)createRadioRoot {
QSection *section1 = [[QSection alloc] initWithTitle:@"Radio element with push"];
[section1 addElement:[[QRadioElement alloc] initWithItems:[NSArray arrayWithObjects:@"Football", @"Soccer", @"Formula 1", nil] selected:0]];
[section1 addElement:[[QRadioElement alloc] initWithItems:[NSArray arrayWithObjects:@"Football", @"Soccer", @"Formula 1", nil] selected:0 title:@"Sport"]];
+ [section1 addElement:[[QRadioElement alloc] initWithDict:[NSDictionary dictionaryWithObjectsAndKeys:@"FerrariObj", @"Ferrari", @"McLarenObj", @"McLaren", @"MercedesObj", @"Mercedes", nil] selected:0 title:@"With Dict"]];
+
QRadioElement *elementWithAction = [[QRadioElement alloc] initWithItems:[NSArray arrayWithObjects:@"Ferrari", @"McLaren", @"Lotus", nil] selected:0 title:@"WithAction"];
elementWithAction.controllerAction = @"exampleAction:";
[section1 addElement:elementWithAction];
@@ -262,7 +264,6 @@ + (QElement *)createRadioRoot {
QSection *section2 = [[QRadioSection alloc] initWithItems:[NSArray arrayWithObjects:@"Football", @"Soccer", @"Formula 1", nil] selected:0 title:@"Sport"];
[root addSection:section2];
-
return root;
}

0 comments on commit 329c50c

Please sign in to comment.