Hallo, liebe Leute!
Ich habe gerade folgendes Problem mit UISegmentedControl:
Wenn der User das Segment klickt, das schon aktiv ist, möchte ich eine Funktion aufrufen.
UIControlEventValueChanged wird ja (ist ja klar) nur aufgerufen, wenn sich was ändert.
Bei stackoverflow habe ich folgendes gefunden
You can use a subclass to get the behavior you want. Make a subclass of UISegmentedControl that has one BOOL ivar:
BOOL _actionSent;
Then, in the implementation, override the following two methods:
- (void)sendAction: (SEL)action to: (id)target forEvent: (UIEvent *)event {
[super sendAction:action to:target forEvent:event];
_actionSent = TRUE;
}
- (void) setSelectedSegmentIndex: (NSInteger)toValue {
_actionSent = FALSE;
[super setSelectedSegmentIndex:toValue];
if (!_actionSent) {
[self sendActionsForControlEvents:UIControlEventValueChanged];
_actionSent = TRUE;
}
}
Funktioniert nur leider nicht.
Wenn ich das mache, wird beim Laden der App die setSelectedSegmentIndex aufgerufen und dann passiert nichts mehr, egal, wie wild ich auf den Segmenten herumflicke.
Kennt vllt. jemand von euch eine andere Variante, oder weiß, wie ich das hinbekommen könnte?
Vielen Dank & liebe Grüße
Julian
Ich habe gerade folgendes Problem mit UISegmentedControl:
Wenn der User das Segment klickt, das schon aktiv ist, möchte ich eine Funktion aufrufen.
UIControlEventValueChanged wird ja (ist ja klar) nur aufgerufen, wenn sich was ändert.
Bei stackoverflow habe ich folgendes gefunden
You can use a subclass to get the behavior you want. Make a subclass of UISegmentedControl that has one BOOL ivar:
BOOL _actionSent;
Then, in the implementation, override the following two methods:
- (void)sendAction: (SEL)action to: (id)target forEvent: (UIEvent *)event {
[super sendAction:action to:target forEvent:event];
_actionSent = TRUE;
}
- (void) setSelectedSegmentIndex: (NSInteger)toValue {
_actionSent = FALSE;
[super setSelectedSegmentIndex:toValue];
if (!_actionSent) {
[self sendActionsForControlEvents:UIControlEventValueChanged];
_actionSent = TRUE;
}
}
Funktioniert nur leider nicht.
Wenn ich das mache, wird beim Laden der App die setSelectedSegmentIndex aufgerufen und dann passiert nichts mehr, egal, wie wild ich auf den Segmenten herumflicke.
Kennt vllt. jemand von euch eine andere Variante, oder weiß, wie ich das hinbekommen könnte?
Vielen Dank & liebe Grüße
Julian