rockstarberlin
rockstarberlin

Reputation: 1853

set highlight of UISegmentedControl

i´d like to set the highlighted segment without calling the assigned function.

i call

segmentedControlLeft.selectedSegmentIndex = 1;

that works well for the segmentedControl but it generates UIControlEventValueChanged as well which calls my attached function and i´d like to avoid it calling again.

is that possible?

thank you!

Upvotes: 0

Views: 2296

Answers (3)

rockstarberlin
rockstarberlin

Reputation: 1853

I did it like this now and it works

[segmentedControlLeft removeTarget:self action:@selector(segmentActionZoom:) forControlEvents:UIControlEventValueChanged];
segmentedControlLeft.selectedSegmentIndex = value;
[segmentedControlLeft addTarget:self action:@selector(segmentActionZoom:) forControlEvents:UIControlEventValueChanged];

Upvotes: 1

zrzka
zrzka

Reputation: 21219

Remove target, change selected segment and add your target again. Or do you use some variable to flag that you did modify it by code and if this flag is set, ignore this call in your function and reset your flag.

Upvotes: 1

Matthias Bauch
Matthias Bauch

Reputation: 90117

See my question

This is a known issue. ID# 8372405

You have to use a BOOL that you set before you use setSelectedSegmentIndex: and unset after you've set the selected index. Check for the bool in your action.

This is what I did.

Upvotes: 2

Related Questions