Skip to content

Commit

Permalink
respond to PR
Browse files Browse the repository at this point in the history
  • Loading branch information
clayallsopp committed Apr 1, 2015
1 parent efc305a commit 67a91e0
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions React/Views/RCTSegmentedControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,43 @@
#import "UIView+React.h"
#import "RCTEventDispatcher.h"


@implementation RCTSegmentedControl
{
RCTEventDispatcher *_eventDispatcher;
}

- (id)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
{
if (self = [super initWithFrame:CGRectZero]) {
if ((self = [super initWithFrame:CGRectZero])) {
_eventDispatcher = eventDispatcher;

[self addTarget:self
action:@selector(onChange:)
forControlEvents:UIControlEventValueChanged];

[self addTarget:self action:@selector(onChange:) forControlEvents:UIControlEventValueChanged];
}
return self;
}


- (void)setValuesAndSelectedValue:(NSDictionary *)valuesAndSelectedValue
{
NSArray *values = valuesAndSelectedValue[@"values"];
[self removeAllSegments];
for (int i = 0; i < values.count; i++) {
[self insertSegmentWithTitle:values[i] atIndex:i animated:NO];

NSArray *values = valuesAndSelectedValue[@"values"];
NSUInteger insertAtIndex = 0;
for (NSString *value in values) {
[self insertSegmentWithTitle:value atIndex:insertAtIndex animated:NO];
insertAtIndex += 1;
}

NSString *selectedValue = valuesAndSelectedValue[@"selectedValue"];
NSInteger segmentIndex = -1;
for (int i = 0; i < self.numberOfSegments; i++) {
NSUInteger selectedSegmentIndex = NSNotFound;
for (NSUInteger i = 0; i < self.numberOfSegments; i++) {
NSString *segmentValue = [self titleForSegmentAtIndex:i];
if ([segmentValue isEqualToString:selectedValue]) {
segmentIndex = i;
selectedSegmentIndex = i;
break;
}
}
if (segmentIndex != -1) {
[self setSelectedSegmentIndex:segmentIndex];
if (selectedSegmentIndex != NSNotFound) {
[self setSelectedSegmentIndex:selectedSegmentIndex];
}
}

Expand Down

0 comments on commit 67a91e0

Please sign in to comment.