UI选项卡栏以编程方式实现UITabbarDelegate

时间:2014-01-07 22:12:40

标签: objective-c delegates barcode uitabbar

我正在尝试对条形码扫描插件进行修改。

我添加了UITabbar按钮。(它不是标签栏控制器)

此代码无效,ı尝试多次但仍然给我错误。这是括号中的错误消息(//tabBar.delegate = self;
      //分配给ID< UITabbarDelegate>来自不兼容的类型CDVbcsViewController)

当我使用点击事件按钮时,我无法使用ıt.But我需要触摸点击事件按钮才能使用。 (didSelectItem)。如何在标签栏应用程序中使用此插件文件。我之前怎么会错误地给出错误。 另外,我正在以编程方式使用uitabbar,我正在等待你的帮助。

CDVBarcodeScanner.mm文件:

UITabBar *tabBar = [[UITabBar alloc] initWithFrame:CGRectMake(0, 430, 320, 49)];

NSMutableArray *tabBarItems = [[NSMutableArray alloc] init];

UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Flight" image:[UIImage imageNamed:@"image-1.png"] tag:0];
UITabBarItem *tabBarItem1 = [[UITabBarItem alloc] initWithTitle:@"Shop" image:[UIImage imageNamed:@"mentionsIcon.png"] tag:1];

UITabBarItem *tabBarItem2 = [[UITabBarItem alloc] initWithTitle:@"Test" image:[UIImage imageNamed:@"lambicon.png"] tag:2];

UITabBarItem *tabBarItem3 = [[UITabBarItem alloc] initWithTitle:@"Other" image:[UIImage imageNamed:@"image-2.png"] tag:3];

[tabBarItems addObject:tabBarItem];
[tabBarItems addObject:tabBarItem1];
[tabBarItems addObject:tabBarItem2];
[tabBarItems addObject:tabBarItem3];

tabBar.items = tabBarItems;
tabBar.selectedItem = [tabBarItems objectAtIndex:0]; 
**//tabBar.delegate = self;**   //here you need import the protocol <UITabBarDelegate>
 // here problem ? Assigning to id <UITabbarDelegate> from incompatible type CDVbcsViewController

[overlayView addSubview:tabBar];

1 个答案:

答案 0 :(得分:0)

您的CDVbcsViewController不符合协议UITabbarDelegate

更改此行

@interface CDVbcsViewController : UIViewController <CDVBarcodeScannerOrientationDelegate> {}

到这个

@interface CDVbcsViewController : UIViewController <CDVBarcodeScannerOrientationDelegate, UITabbarDelegate> {}

并在UITabbarDelegate

中实施CDVbcsViewController的方法