I started objective C today and for the last hour I’ve been trying to work out how to switch an image when I click a button, It’s a segmenting button with 2 segments, first segment should load 0.jpg, second segment should load 1.jpg.
I can get it to change from 0->1 but not back, so it’s as if only the first switch is being registered, any ideas?
(As you can see, i’ve tried debugging, everything should check out:
2012-05-25 13:22:31.173 Clock2[3398:f803] Segment clicked: 0
2012-05-25 13:22:31.174 Clock2[3398:f803] 0.jpg
2012-05-25 13:22:31.367 Clock2[3398:f803] Segment clicked: 1
2012-05-25 13:22:31.368 Clock2[3398:f803] 1.jpg
.
- (IBAction)clockselect:(id)sender {
NSString* segindex= [NSString stringWithFormat:@"%d", clockselectout.selectedSegmentIndex];
NSString* type= @".jpg";
NSString* filename= [segindex stringByAppendingString:type ];
if (clockselectout.selectedSegmentIndex == '0') {
NSLog(@"Segment clicked: %d", clockselectout.selectedSegmentIndex);
// NSLog(filename);
[clockimg setImage:[UIImage imageNamed: filename]];
} else {
NSLog(@"Segment clicked: %d", clockselectout.selectedSegmentIndex);
// NSLog(filename);
[clockimg setImage:[UIImage imageNamed: filename]];
}
}
1 Answer