我有一个导航 Controller ,它利用 if 语句在不同的 View 之间切换,当我运行它时,它会在该行发出警告:
ROSS_APP_7AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
警告:类型“id”不符合“UITabBarControllerDelegate”协议(protocol)
我需要一些关于如何摆脱这个警告的帮助。 这是整个 if 语句:
if(indexPath.row == 0)
{
MapDetailController *mapD = [[MapDetailController alloc] initWithNibName:@"MapDetailController" bundle:nil];
self.mapDetailController = mapD;
[mapD release];
mapDetailController.title = [NSString stringWithFormat:@"%@", [moreArray objectAtIndex:row]];
ROSS_APP_7AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.moreNavController pushViewController:mapDetailController animated:YES];
}
谢谢
编辑: 这是我的 AppDelegate 的样子(对答案 #2 的回应)
#import <UIKit/UIKit.h>
@class MoreNavController;
@interface ROSS_APP_7AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
IBOutlet UITabBarController *tabBarController;
IBOutlet MoreNavController *moreNavController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@property (nonatomic, retain) IBOutlet MoreNavController *moreNavController;
@end
最佳答案
您可能忘记让您的应用委托(delegate)符合 UITabBarControllerDelegate 协议(protocol)。
要实现它,您的 appDelegate header 应如下所示(@interface 声明是相关行):
#import ...
@interface ROSS_APP_7AppDelegate : AppDelegate_Shared <UITabBarControllerDelegate>
{
....
}
@property(nonatomic, retain) .....
@end
您可能正在使用 AppDelegate_Shared/AppDelegate_iPhone/AppDelegate_iPad 所以请记住,上面的示例考虑的是共享应用委托(delegate)
编辑:
看到你的评论后,
尝试替换:
ROSS_APP_7AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
有了这个:
ROSS_APP_7AppDelegate *delegate = (ROSS_APP_7AppDelegate*)[[UIApplication sharedApplication] delegate];
像这样对返回值进行类型转换是否可以消除警告?
关于iphone - Xcode - 警告问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6272326/