我有一个导航控制器,它使用if语句在不同的视图之间切换,当我运行它时会在行上显示警告:
ROSS_APP_7AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
警告:类型'id'不符合'UITabBarControllerDelegate'协议
我想要了解如何摆脱这种警告。 这是整个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
答案 0 :(得分:3)
您可能忘记让您的app委托符合UITabBarControllerDelegate协议。
要实现它,你的appDelegate标题应如下所示(@interface声明是相关的行):
#import ...
@interface ROSS_APP_7AppDelegate : AppDelegate_Shared <UITabBarControllerDelegate>
{
....
}
@property(nonatomic, retain) .....
@end
您可能正在使用AppDelegate_Shared / AppDelegate_iPhone / AppDelegate_iPad,因此请记住上述示例考虑了共享应用代理
编辑:
看到你的评论后,
尝试更换:
ROSS_APP_7AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
有了这个:
ROSS_APP_7AppDelegate *delegate = (ROSS_APP_7AppDelegate*)[[UIApplication sharedApplication] delegate];
对这样的回报进行类型转换可以消除你的警告吗?
答案 1 :(得分:0)
您是否尝试过铸造委托,如下所示:
(id)[[UIApplication sharedApplication] delegate];
???