I connected a UISegmentedControl object from the .xib file to the corresponding IBOutle UISegmentedControl ivar in the ViewController.h. Then I put this method in the ViewController.m:
-(IBAction)switchMapTypes {
if (switchMapTypes.selectedSegmentIndex == 0)
[worldView setMapType: MKMapTypeStandard];
else if (switchMapTypes.selectedSegmentIndex == 1)
[worldView setMapType: MKMapTypeSatellite];
else if (switchMapTypes.selectedSegmentIndex == 2)
[worldView setMapType: MKMapTypeHybrid];
}
Will this cause a retain cycle if I link this method back to the UISegmentedControl object in the .xib file? Or am I completely misunderstanding what a retain cycle is?
A retain cycle happens when an object owns another object that in turn owns the first. Your segemented control doesn’t claim ownership of the view controller — hooking up an
IBActionhas no ownership consequences — so there’s no cycle here.There’s a style issue, though. You appear to have a method which is not a getter that has the same name as an ivar,
switchMapTypes. You should not use the same name for two such different things. Also, your ivar name should really be a noun, and the method (which is an action) a verb. I would suggestmapTypesSwitchfor the ivar andchangeMapTypefor the action.