gpt4 book ai didi

iphone - 如何符合 UITabBarControllerDelegate

转载 作者:太空狗 更新时间:2023-10-30 03:40:01 25 4
gpt4 key购买 nike

我有一个基于标签栏的应用程序并执行以下操作以获取对应用程序委托(delegate)的引用:

MyAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];

然后给出这个警告:

warning: type 'id <UIApplicationDelegate>' does not conform to the 'UITabBarControllerDelegate' 

我的应用程序委托(delegate) header 如下所示:

#import <UIKit/UIKit.h>

@interface MyAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

@end

.m 文件中仅有的方法是 applicationDidFinishLaunching 和 dealloc。我还需要什么来遵守协议(protocol)?

最佳答案

这是静态警告。说明[[UIApplication sharedApplication] delegate]的返回类型不符合tab bar delegate协议(protocol),是的。

转换从 [[UIApplication sharedApplication] delegate] 返回的值来消除警告:

MyAppDelegate *appDelegate = (MyAppDelegate*)[[UIApplication sharedApplication] delegate];

关于iphone - 如何符合 UITabBarControllerDelegate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2214613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com