iPhone SDK warning: class MyAppViewController does not implement the 'UITabbarDelegate' protocol

二次信任 提交于 2019-12-12 01:18:24

问题


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

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


回答1:


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:

implement that and you'll be fine.

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

@interface MyDelegate <UITabBarDelegate>


来源:https://stackoverflow.com/questions/1788882/iphone-sdk-warning-class-myappviewcontroller-does-not-implement-the-uitabbarde

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!