Can't connect Segmented Control to its IBOutlet

I have created a segmented control in the interface builder.

In my ViewController.h:

@interface ViewController : UIViewController <MKMapViewDelegate>
@property IBOutlet UISegmentedControl *Segment;
- (IBAction)switchMode:(id)sender;
@end

      

What I could do is connect the Segmented Control with IBAction, but I cannot connect it to the IBOutlet!

+3


source to share


3 answers


  • Add segmented control to panel / storyboard
  • Add the following code to .h

@property(nonatomic,retain) IBOutlet UISegmentedControl *Segment;



  • In your storyboard or xib, make sure the owner of the file has the same class name as the class where you wrote the output
  • Right click on segmantControl and a window with exits and actions will appear.
  • click and drag the link and drop it on the filename . A new pop will appear that includes your output entry written in code and select it.

Connection established

+6


source


you forgot to write property parameters, correct it like below code

@property(nonatomic,retain) IBOutlet UISegmentedControl *Segment;

      



after that synthesize this property in .m file like this

@Synthesize Segment;

      

0


source


It looks like with some xCode update you can no longer connect certain outputs to your .h. You should be well connected to it .m though:

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UISegmentedControl *mySegmentedController;
@end

      

I'll read some docs and see when that changes. There is also no reason to wire this property to your public interface (hence why this is no longer allowed). Only the View Controller of this class should have control over it.

0


source







All Articles