xcodeを4.5にバージョンアップした際に、「Enumeration values ‘NSTextAlignmentJustified’ and ‘NSTextAlignmentNatural’ not handled in switch」という警告文が出た時の解消策。
環境
iOS6Xcode4.5
cocos2d1.x
解決方法
エラーが出ている箇所はFontLabel.mの中の「– (void)drawTextInRect:(CGRect)rect」メソッドの中と、FontLabelStringDrawing.mの「drawOrSizeTextConstrainedToSize」中の2箇所です。コードは以下のようになっていると思います。
[- (void)drawTextInRect:(CGRect)rect]の方
1 2 3 4 5 6 7 8 9 10 |
switch (self.textAlignment) { case UITextAlignmentLeft: break; case UITextAlignmentCenter: point.x += (origSize.width - size.width) / 2.0f; break; case UITextAlignmentRight: point.x += origSize.width - size.width; break; } |
[drawOrSizeTextConstrainedToSizeの方]
1 2 3 4 5 6 7 8 9 10 11 12 |
if (performDraw) { switch (alignment) { case UITextAlignmentLeft: drawPoint.x = 0; break; case UITextAlignmentCenter: drawPoint.x = (constrainedSize.width - lineSize.width) / 2.0f; break; case UITextAlignmentRight: drawPoint.x = constrainedSize.width - lineSize.width; break; } |
swich構文の中に、defaultの選択肢を用意してあげれば警告は消えます。
変更したコードは以下のようになります。
1 2 3 4 5 6 7 8 9 10 11 12 |
switch (self.textAlignment) { case UITextAlignmentLeft: break; case UITextAlignmentCenter: point.x += (origSize.width - size.width) / 2.0f; break; case UITextAlignmentRight: point.x += origSize.width - size.width; default: //これを追加する break; } |
いかがでしょうか。
私も最近xcode4.5に変更したら、エラーは出ないのですが警告がたくさん出てきました。
OSのバージョンアップがあれば、こういった不具合が必ずでてきますので、大変ですね。
[参考サイト]
