I have a UISegmentedControl within a view both within a xib. In my app delegate I am creating the controller which is the file’s owner of the xib using initWithNibName: and then wrapping it within a navigation controller (UINavigationController initWithRootViewController).
Then I try to set either the image or title of elements within the segmented control like this:
[self.viewController.segmentControl setImage: [UIImage imageNamed:@"some_image.png"]forSegmentAtIndex: 3];
[self.viewController.segmentControl setTitle: @"some text" forSegmentAtIndex: 2];
The segmented control is appearing but the setImage: and setTitle: is having no effect.
The first two cells say First and Second respectively which are the default values assigned when initially drag/dropping it within IB.
segmentControl is an IBOutlet and I’ve confirmed its connected to the segmented control.
Why is it not working?
I can set the image or text in IB and it works, but I would like to understand why I cannot set them programatically.
(The segmented control has 6 indexes).
Why are you setting up the segmented control in your app delegate? Shouldn’t you be adjusting it’s attributes in the file’s owner (viewController)? I would probably do this in viewController’s viewDidLoad method, or since you’re using IB anyway, simply set the image and title attributes there (in your XIB).