开发者

set highlight of UISegmentedControl

开发者 https://www.devze.com 2023-02-14 17:12 出处:网络
i´d like to set the highlighted segment without calling the assigned function. i call segmentedContr开发者_运维百科olLeft.selectedSegmentIndex = 1;

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

i call

segmentedContr开发者_运维百科olLeft.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!


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.


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.


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];
0

精彩评论

暂无评论...
验证码 换一张
取 消