views:

1363

answers:

1

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.

+2  A: 

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>
Neil Foley
I have already implemented the tabBar:didSelectItem method, and declared in the header file too. Can you just tell me about the last line in your reply? I didnt get it. thanks..
pMan
i've updated the answer with an example
Neil Foley
perfect...that was the only problem, and 15 points for your help! :)
pMan
Thanks a lot :) One last thing, you don't need the message signature in your header file if you declare you implement the delegate, but thers not harm in having it.
Neil Foley