Reputation:
I'm having a little difficulty with the UISegmentedControl and can't find what is causing this issue.
The problem is the segmentChange method completely ignores the else if
statement and just calls the poundValueSelected method.
ViewController1 is the child class and the viewController is the parent class.
Why is this happening?
[self.productCoreDetailView.segement addTarget:self.productViewController action:@selector(segmentChange) forControlEvents:UIControlEventValueChanged];
View Controller:
-(void)segmentChange{
if (self.productCoreDetailView.segement.selectedSegmentIndex == 0 ) {
[self poundValueSelected];
} else if (self.productCoreDetailView.segement.selectedSegmentIndex == 1) {
[self euroValueSelected];
}
Picture of the segment control:
Upvotes: 2
Views: 1534
Reputation: 3606
I think you are not sending the sender of this action that is your segment control, so try this code:
[self.productCoreDetailView.segement addTarget:self.productViewController action:@selector(segmentChange:) forControlEvents:UIControlEventValueChanged];
-(void)segmentChange:(UISegmentedControl *)sender{
if (sender.selectedSegmentIndex == 0 ) {
[self poundValueSelected];
} else if (sender.selectedSegmentIndex == 1) {
[self euroValueSelected];
}
}
Upvotes: 4