【问题标题】:Unable to access method in the delegate无法访问委托中的方法
【发布时间】:2010-11-15 21:09:33
【问题描述】:

以下是我设置应用的方式。我有一个根视图,它在 viewDidLoad 方法期间在其顶部加载一个子视图。在子视图中,我有一个按钮,单击该按钮时会隐藏自身并显示根视图。一切都很好,但我讨厌有一个已加载但未使用的视图。我试图在委托中放置一个方法来执行此操作:

[theLaunch release];

...theLaunch 是我的子视图。

此方法位于我的委托中,称为hidetheLaunch

然后我试图从子视图中调用此方法:

[[UIApplication sharedApplication].delegate hidetheLaunch];

但上面写着-hidetheLaunch not found in protocol

我做错了吗?

提前致谢!

【问题讨论】:

    标签: iphone objective-c memory-management delegates subview


    【解决方案1】:

    您需要先UIApplicationDelegate 转换为您的特定代表的类型:

    [((MyAppDelegate *) [UIApplication sharedApplication].delegate) hidetheLaunch];
    

    【讨论】:

    • 当我将我的代表名称替换为您提供的代码时,它说它没有被声明。我需要#import 代表吗?
    • 好吧,每当我导入 Delegate 时,都会导致整个应用程序出现错误。我只是决定完全跳过整个事情。 :)
    • @willingfamily 这没有意义。请告诉我们您遇到的错误。
    • 导入委托后,我的RootViewController.mSlideToLaunchAppDelegate.mfirstLaunch.m 中出现错误。我得到的错误是:Expected specifier-qualifier-list before firstLaunch`。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-11
    相关资源
    最近更新 更多