@ 7 केवी 7 ने मुझे सोच लिया। मैंने उन पसंदीदा चित्रों और चित्रों को चिह्नित करने के लिए उपयोग करना चाहता हूं जिन्हें मैं कभी नहीं देखना चाहता हूं। मैंने बटन को आरंभ करने के लिए अपनी विधि का उपयोग किया और फिर बटन को चालू और बंद करने के लिए अपनी विधि को थोड़ा संशोधित किया।
इस उदाहरण में, यदि आप एक तस्वीर को पसंदीदा के रूप में चिह्नित करते हैं, तो आप अनदेखा बटन को बंद करना चाहते हैं और इसके विपरीत। प्रतिनिधि डेटाबेस सामान को संभालता है।
self.favoriteButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.ignoreButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.favoriteButton setImage:[UIImage imageNamed:@"Favorite-Selected"]
forState:UIControlStateSelected];
[self.favoriteButton setImage:[UIImage imageNamed:@"Favorite"]
forState:UIControlStateNormal];
[self.ignoreButton setImage:[UIImage imageNamed:@"Ignore-Selected"]
forState:UIControlStateSelected];
[self.ignoreButton setImage:[UIImage imageNamed:@"Ignore"]
forState:UIControlStateNormal];
तुम सिर्फ चालू या बंद एक बटन टॉगल रहे हैं, तो आप इसे एक संपत्ति बनाने के लिए, के बाद से buttonPressed इस जानता है जो बटन दबाया गया है की जरूरत नहीं होगी। मुझे उन्हें संपत्ति होने की ज़रूरत है क्योंकि मुझे इसके हाइलाइट को बंद करने के लिए विपरीत बटन बताने की ज़रूरत है।
- (void)favoriteIgnore:(UIButton *)buttonPressed {
// Toggle the tapped button
buttonPressed.selected = (buttonPressed.selected) ? NO : YES;
id <ScoringToolbarDelegate> TB_delegate = _delegate;
// Turn off the other button and call the delegate
if ([buttonPressed.currentTitle isEqualToString:@"favorite"]) {
self.ignoreButton.selected = NO;
[TB_delegate favoriteButtonPressed];
} else {
self.favoriteButton.selected = NO;
[TB_delegate ignoreButtonPressed];
}
}
मेरा उत्तर जाँच .. – Jhaliya