2009-11-24 44 views
0

我在一个iPhone应用程序上工作,没有使用IB,并且在基于视图的应用程序中以UIViewController的三个项目以编程方式创建了一个UITabbar,我使用了一个委托方法,如果没有下面代码片段中的最后一行(setDelegate方法),那将无法工作。我没有一个tabbarviewcontroller。iPhone SDK警告:类MyAppViewController没有实现'UITabbarDelegate'协议

UITabBar *tabbar = [[UITabBar alloc] initWithFrame:CGRectMake(0, YMAX-60, XMAX, 40)]; 

    NSMutableArray *items = [[NSMutableArray alloc] initWithCapacity:3]; 
    [items addObject:[[[UITabBarItem alloc] initWithTitle:@"One" image:[UIImage imageNamed:@"img04.png"] tag:0] autorelease]]; 
    [items addObject:[[[UITabBarItem alloc] initWithTitle:@"Two" image:[UIImage imageNamed:@"img.png"] tag:1] autorelease]]; 
    [items addObject:[[[UITabBarItem alloc] initWithTitle:@"Three" image:[UIImage imageNamed:@"img-01.png"] tag:2] autorelease]]; 

    tabbar.items = items; 
    tabbar.alpha = 1.0; 
    tabbar.userInteractionEnabled = YES; 
    [tabbar setBackgroundColor:[UIColor blueColor]]; 
    [tabbar setDelegate:self]; 

是否可以消除此警告?我不是可可程序员,有时需要在iphone上工作。

回答

5

要摆脱此警告,您必须实现UItabBarDelegate协议所需的一个方法。

UITabBarDelegate_Protocol

你可以看到,所需要的方法是:

– tabBar:didSelectItem: 

实现这一点,你会没事的。

不要忘记在你的头文件中声明你实现了协议。

@interface MyDelegate <UITabBarDelegate> 
+0

我已经实现了tabBar:didSelectItem方法,并在头文件中声明。你能告诉我关于你答复的最后一行吗?我没有得到它。谢谢.. – pMan 2009-11-24 09:45:13

+0

我已经用示例更新了答案 – 2009-11-24 09:55:46

+0

完美...这是唯一的问题,并为您的帮助15点! :) – pMan 2009-11-24 09:58:50

相关问题