Lucky Setiadarma
Lucky Setiadarma

Reputation: 71

UISegmentedControl event does not work properly

I am currently working with a UISegmentedControl with 2 selections here. I have already defined it in -(void)viewDidLoad:

_segmentSelector = [[UISegmentedControl alloc] initWithItems:_selectorItems];
_segmentSelector.frame = CGRectMake(40, 356, 200, 43);
_segmentSelector.segmentedControlStyle = UISegmentedControlStyleBezeled;
_segmentSelector.selectedSegmentIndex = 0; 
[_segmentSelector addTarget:self  
                     action:@selector(selectorValueChanged)
           forControlEvents:UIControlEventValueChanged];

The action for @selector(selectorValueChanged) is as following:

 - (void)selectorValueChanged
 {
     if(_segmentSelector.selectedSegmentIndex=1)
     {

     }
     if(_segmentSelector.selectedSegmentIndex=0)
     {

     }
 }

My problem is, that when i run a simulation and clicked on one button, then attempted to click another button, the SegmentedControl does not respond. It stays on the selection and refuses to accept another tap/click/whatever action i ordered it to. What is wrong with it?

Upvotes: 1

Views: 281

Answers (1)

Martin R
Martin R

Reputation: 539685

In selectorValueChanged, you assign new values to the selected segment index:

if (_segmentSelector.selectedSegmentIndex = 1)

Your probably mean

if (_segmentSelector.selectedSegmentIndex == 1)

Upvotes: 3

Related Questions