Reputation: 3827
So I have a strange problem with my segmented control I am trying to use. Essentially I have a preferences panel that displays via a popover when a button is pushed.
The problem: I am trying to save the state so when the view loads, the segmented control should save it's selected item. Here is what I am doing so far...
-(void)viewWillAppear:(BOOL)animated {
if(!self.mainViewController.isThreaded){
self.threadedView.selectedSegmentIndex == 0;
//[self.threadedView setSelectedSegmentIndex:0];
//I can't do this because if I do it, it rexecutes the changeSegment method,
// which I do not want
}
if(self.mainViewController.isThreaded){
self.threadedView.selectedSegmentIndex == 1;
//[self.threadedView setSelectedSegmentIndex:1];
}
//threadedView.momentary = NO;
}
-(void)changeSegment {
if(self.threadedView.selectedSegmentIndex == 0){
self.mainViewController.isThreaded = NO;
[self.threadedView setSelectedSegmentIndex:0];
}
if(self.threadedView.selectedSegmentIndex == 1){
self.mainViewController.isThreaded = YES;
[self.threadedView setSelectedSegmentIndex:1];
}
}
now the problem is, when the popover appears, it does not load the state to the segmented control, as I understand it should. Can anyone point out what I may be doing wrong? Thanks
Upvotes: 0
Views: 1140
Reputation: 4989
In viewWillAppear, if you want to set them and not test them it should be:
self.threadedView.selectedSegmentIndex = 0/1;
not
self.threadedView.selectedSegmentIndex == 0/1;
, unless I'm missing something.
Upvotes: 2