@7KV7 让我思考。我有最喜欢和忽略的按钮,我想用它们来标记最喜欢的图片和我再也不想看到的图片。我使用他的方法来初始化按钮,然后稍微修改他的方法来打开和关闭按钮。
在此示例中,如果您将图片标记为收藏,您希望关闭忽略按钮,反之亦然。委托处理数据库的东西。
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];
}
}