It does not work because UISegmentedControl
has selectedSegmentIndex
property, not selectedIndex
:
switch ([sender selectedSegmentIndex]) { // <<== Here
case 0:
label.text = @"Case Zero :)";
break;
case 1:
label.text = @"Happy New Year!";
break;
default:
label.text = @"Press a button:";
break;
}
Sometimes, Xcode lets you pick a wrong method; when you are not certain of the exact name, consult developer documentation available online and through Xcode's Help/Documentation and API Reference.