まず、すべてのプレーヤーのリストが必要です。それがこれであると仮定しましょう:
NSMutableArray *_allplayers = ...;
次に、メソッドで、話題になっているプレーヤーを除いて、すべてのプレーヤーを非アクティブに設定できます。
- (void) playerBuzzedIn: (XGPlayer *) activePlayer
{
if (activePlayer)
{
for (XGPlayer *player in _allPlayers)
{
player.isActive = activePlayer == player; // Or perhaps [activePlayer isEqual:player] ?
}
}
self.currentGameState = results;
}
もう 1 つの方法は、現在アクティブなプレーヤーへのポインタを保持することです。
.h ファイル内:
@interface Whatever : NSObject
{
XGPlayer *_activePlayer = nil;
}
@property (retain, nonatomic, readonly) XGPlayer *activePlayer;
@end
.m ファイル内:
// Private Methods
@interface Whatever ()
- (void)setActivePlayer:(XGPlayer *)activePlayer
@end
@implementation Whatever
@synthesize activePlayer = _activePlayer;
// Private setter method
- (void)setActivePlayer:(XGPlayer *)activePlayer
{
[activePlayer retain]; // If not using ARC
[_activePlayer release]; // If not using ARC
_activePlayer = activePlayer;
}
- (void) playerBuzzedIn: (XGPlayer *) activePlayer
{
self.activePlayer.isActive = NO;
activePlayer.isActive = YES;
self.activePlayer = activePlayer;
self.currentGameState = results;
}