【问题标题】:Suppress Xcode incompatible pointer type for subclass of UIViewController为 UIViewController 的子类抑制 Xcode 不兼容的指针类型
【发布时间】:2012-08-06 17:50:00
【问题描述】:

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

SurveyQuestion *currentQuestionController = [self.navigationController visibleViewController];

一切正常,但 Xcode 给了我一个警告

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

我知道这是因为 visibleViewController 返回一个 UIViewController,但它可以工作,因为 SurveyQuestion 是一个 UIViewController。有没有办法抑制这个错误?还是我应该换一种方式?

【问题讨论】:

    标签: objective-c ios xcode uiviewcontroller


    【解决方案1】:

    你可以使用 cast like

    SurveyQuestion *currentQuestionController = (SurveyQuestion *)[self.navigationController visibleViewController];
    

    【讨论】:

    • 呃,我肯定是想多了
    猜你喜欢
    • 2011-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多