I have some UIPopoverViewControllers
that do messaging to delegate UIViewControllers
to pass UI events. Instead of writing a separate method for each event, I have a method in the delegate with a switch statement which determines how to handle the event based on a passed constant (example below).
This is probably poor design but it is what I've come up with. I've seen this question regarding enums or static classes but didn't understand the answers.
So..is what I am doing BAD and is there a way I can define the enums in one place so that I don't have to maintain multiple bits of code that can easily get out of sync?
EDIT Okay, digging around a bit more (here + here) I see that I might be on the right track. So I guess I need to know what and where an implementation
file is in iOS.
enum {
kSetPlaybackType = 0,
kSetAllNotesOn,
kSetAllNotesOff,
kSetVelocity,
kSetDuration
};
- (void)barPropertyAction:(int)action withParam:(NSNumber *)param
{
switch (action) {
case kSetPlaybackType:
playbackType = [param intValue];
if (playbackType == kPalindrome){
palindromeDirection = kPalindromeUp;
}
break;
case kSetAllNotesOn:
for (BarNote* note in self.barNoteArray) {
note.noteOn = YES;
}
[self.bar updateWindows];
break;
case kSetAllNotesOff:
for (BarNote* note in self.barNoteArray) {
note.noteOn = NO;
}
[self.bar updateWindows];
break;
case kSetVelocity:
for (BarNote* note in self.barNoteArray) {
note.velocity = [param intValue];
}
break;
case kSetDuration:
for (BarNote* note in self.barNoteArray) {
note.duration = [param floatValue];
}
break;
default:
break;
}
}