What might one suggest as a good way to derive the selected index of a UISegmentedControl
Does anyone have any suggestions for an 'Apple Sanctioned' way to change behaviors (ie, showing specific pictures in an imageView) based upon which segment within a UISegmentedControl is selected? Should a case or switch statement be used?
Forgive the possible obscenely obvious question, but I was instructed that if you need to use a switch or case statement within an object, you probably need to create additinal object, sut I do not think that this rubric applies in this cse, correct?
Thanks for any and all suggestions, and your consideration.
开发者_运维问答(I'm using Xcode 3.2, iOS 4 SDK)
You can use a switch
or if
statement if you like. I don't think there's any "Apple sanctioned" way of doing it.
I have no idea what you mean by
I was instructed that if you need to use a switch or case statement within an object you probably need to create additinal object
Never heard that one before.
Anyway, based on your description of what you want to achieve it should be as easy as
UISegmentedControl *seg = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Seg 1", @"Seg2", nil]] autorelease];
UIImageView *imgView = [[[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:path]] autorelease];
switch (seg.selectedSegmentIndex) {
case 0:
imgView.image = [UIImage imageWithContentsOfFile:alt_path];
break;
case 1:
imgView.image = [UIImage imageWithContentsOfFile:differentPath];
break;
default:
break;
}
精彩评论