2013年冬からiOSの講義(Paul Hegertyによる)を見てきましたが、Matchisimoプログラムでこの2行目のコードが必要な理由に頭を悩ませているようには見えません。コメントアウトするとプログラムがクラッシュしますが、そのままにしておくと問題なく動作します。
[cardButton setTitle:card.contents forState:UIControlStateSelected];
[cardButton setTitle:card.contents forState:UIControlStateSelected|UIControlStateDisabled];
この行で失敗します:
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([CardGameAppDelegate class]));
}
2行目がコメントアウトされている場合にエラーが発生します:
'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 47 beyond bounds [0 .. 46]'
カードの内容:
@property (strong, nonatomic) NSString *contents;
UIの更新:
- (void)updateUI
{
for (UIButton *cardButton in self.cardButtons) {
Card *card = [self.game cardAtIndex:[self.cardButtons indexOfObject:cardButton]];
[cardButton setTitle:card.contents forState:UIControlStateSelected];
[cardButton setTitle:card.contents forState:UIControlStateSelected|UIControlStateDisabled];
cardButton.selected = card.isFaceUp;
cardButton.enabled = !card.isUnPlayable;
}
}