Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Another solution might be using a category:</p> <pre><code>#import &lt;UIKit/UISegmentedControl.h&gt; @interface UISegmentedControl (MultiSelect) @end </code></pre> <p>Doing this, you have in principle access to private member variables of UISegmentedControl . In particular, you have access to the array holding the button segments, which you can manipulate according to your needs by overriding setSelectedSegmentIndex:selectedSegmentIndex: .However, for various reasons, the attributes declared as private still shouldn't be accessed directly, see <a href="https://stackoverflow.com/questions/4429226/accessing-private-variable-in-category-results-in-linker-error">this link</a>. As also suggested there, you can rather abuse KVC. So the implementation could look as follows:</p> <pre><code>@implementation UISegmentedControl (MultiSelect) - (void)setSelectedSegmentIndex:(NSInteger)selectedSegmentIndex { NSMutableArray *pArraySegments = [self valueForKey:@"segments"]; if ((pArraySegments) &amp;&amp; (selectedSegmentIndex &gt;= 0) &amp;&amp; (selectedSegmentIndex &lt; [pArraySegments count])) { UIButton *pSegment = (UIButton*)[pArraySegments objectAtIndex:selectedSegmentIndex]; pSegment.selected ? (pSegment.selected = NO) : (pSegment.selected = YES); } } @end </code></pre> <p>This works for me. However, since I now read <a href="https://stackoverflow.com/questions/633924/uisegmentedcontrol-behaviour">this discussion</a>, I'm not quite sure if this is really a valid approach.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload