2

我有一个 UIViewController 的子类,称为 SurveyQuestion。我为我的应用程序使用了这些数组。我用这条线得到了当前可见的控制器:

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

你可以使用 cast like

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