Search code examples
objective-cnsmutablearrayuisegmentedcontrol

Change number of segments according the arraycount?


I have seen many Questions and still i didn't get exact response I need. Is it possible to change the number of segments in UISegmented control based on array count. When I tried it is showing error:"assigning to readonly property".


Solution

  • Did you try that:

    - (void)setSegments:(NSArray *)segments {
        [segmentController removeAllSegments];
    
        for (NSString *segment in segments) {
            [segmentController insertSegmentWithTitle:segment atIndex:segmentController.numberOfSegments animated:NO];
        }
    }