iPhone SDK警告:类MyAppViewController不实现'UITabbarDelegate'协议 [英] iPhone SDK warning: class MyAppViewController does not implement the 'UITabbarDelegate' protocol

查看:210
本文介绍了iPhone SDK警告:类MyAppViewController不实现'UITabbarDelegate'协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Im working on an iPhone app, not using IB, and programmatically created a UITabbar with three items in a UIViewController in a view based application, I used one delegate method, that wont work without the last line in the snippet below( setDelegate method). I dont have a 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上工作。

Is it possible to eliminate this warning? I am not a Cocoa programmer, sometimes need to work on iphone.

推荐答案

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

To get rid of this warning you must implement the one required method of the UItabBarDelegate protocol.

UITabBarDelegate_Protocol

您可以看到所需的方法是:

You can see that the required method is:

– tabBar:didSelectItem:

实现

别忘了在头文件中声明您已实现协议。

Don't forget to declare in your header file that you implement the protocol.

@interface MyDelegate <UITabBarDelegate>

这篇关于iPhone SDK警告:类MyAppViewController不实现'UITabbarDelegate'协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆