ios - UISegmentedController not changing UIImageView -
i new , use help. have 5 segment controller first button acknowledged. other buttons not seem work. have tried code both under
-(ibaction)segmentbutton:(id)sender
and
-(void)viewdidload
also can tell last segment different code tried no luck. if there better way format know of, feel free share!
if (selector.selectedsegmentindex == 0) { ball.image = [uiimage imagenamed:@"ball2fire.png"]; } if (selector.selectedsegmentindex == 1) { ball.image = [uiimage imagenamed:@"ball2"]; } if (selector.selectedsegmentindex == 2) { ball.image = [uiimage imagenamed:@"ball70color"]; } if (selector.selectedsegmentindex == 3) { ball.image = [uiimage imagenamed:@"ball2b.png"]; } if (selector.selectedsegmentindex == 4) { [ball setimage:[uiimage imagenamed: @"ball2r.png"]]; }
from question, looks you've put code change picture within viewdidload
method? wrong. viewdidload called once, when view loaded. code needs go within ibaction method segmentedcontrol -
-(ibaction)segmentbutton:(uisegmentedcontrol)sender{ if (sender.selectedsegmentindex == 0) { ball.image = [uiimage imagenamed:@"ball2fire.png"]; } if (sender.selectedsegmentindex == 1) { ball.image = [uiimage imagenamed:@"ball2"]; } if (sender.selectedsegmentindex == 2) { ball.image = [uiimage imagenamed:@"ball70color"]; } if (sender.selectedsegmentindex == 3) { ball.image = [uiimage imagenamed:@"ball2b.png"]; } if (sender.selectedsegmentindex == 4) { [ball setimage:[uiimage imagenamed: @"ball2r.png"]]; } }
please note, when segmented control ctrl dragged view class file create segmentedcontrol ibaction, select object type uisegmentedcontrol
object, opposed id
in way can use properties of object, notice within each if statement code can changed to if (sender.selectedsegmentindex....
see picture -
Comments
Post a Comment