【问题标题】:iPhone SDK warning: class MyAppViewController does not implement the 'UITabbarDelegate' protocoliPhone SDK 警告:MyAppViewController 类未实现“UITabbarDelegate”协议
【发布时间】:2009-11-24 09:19:03
【问题描述】:

我正在开发一个 iPhone 应用程序,不使用 IB,并以编程方式在基于视图的应用程序的 UIViewController 中创建了一个包含三个项目的 UITabbar,我使用了一个委托方法,如果没有下面 sn-p 中的最后一行,它将无法工作( setDelegate 方法)。我没有 tabbarviewcontroller。

    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];

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

【问题讨论】:

    标签: iphone compiler-warnings uitabbar


    【解决方案1】:

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

    UITabBarDelegate_Protocol

    可以看到需要的方法是:

    – tabBar:didSelectItem:
    

    实现它,你会没事的。

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

    @interface MyDelegate <UITabBarDelegate>
    

    【讨论】:

    • 我已经实现了tabBar:didSelectItem方法,并且在头文件中也声明了。你能告诉我你回复的最后一行吗?我没明白。谢谢..
    • 完美...这是唯一的问题,15分给你的帮助! :)
    • 非常感谢 :) 最后一件事,如果您声明实现了委托,则不需要在头文件中包含消息签名,但拥有它并没有什么坏处。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-30
    • 1970-01-01
    • 2016-06-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多