2

SurveyQuestion という UIViewController のサブクラスがあります。私は自分のアプリにこれらの配列を使用しています。次の行で現在表示されているコントローラーを取得します。

SurveyQuestion *currentQuestionController = [self.navigationController visibleViewController];

すべてが機能しますが、Xcode から次の警告が表示されます

Incompatible pointer types initializing 'SurveyQuestion *__strong' with an expression of type 'UIViewController *'

これは、visibleViewController が UIViewController を返すためだとわかっていますが、SurveyQuestion が UIViewController であるため機能します。このエラーを抑制する方法はありますか? それとも、別の方法で行う必要がありますか?

4

1 に答える 1

14

次のようにキャストを使用できます

SurveyQuestion *currentQuestionController = (SurveyQuestion *)[self.navigationController visibleViewController];
于 2012-08-06T17:52:10.920 に答える