【问题标题】:UI Tab Bar programmatically implement UITabbarDelegateUI Tab Bar 以编程方式实现 UITabbarDelegate
【发布时间】:2023-03-25 00:58:01
【问题描述】:

我正在尝试修改phonegap条码扫描插件。

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

此代码不起作用,我尝试了很多次但仍然给我错误。这是括号中的错误消息(//tabBar.delegate = self;
// 分配给 id 从不兼容的类型 CDVbcsViewController)

当我使用点击事件按钮时,我不能使用ıt。但是我需要触摸点击事件按钮才能使用。 (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];

【问题讨论】:

标签: objective-c delegates barcode uitabbar


【解决方案1】:

您的CDVbcsViewController 不符合协议UITabbarDelegate

改变这一行

@interface CDVbcsViewController : UIViewController <CDVBarcodeScannerOrientationDelegate> {}

到这里

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

并在CDVbcsViewController中实现UITabbarDelegate的方法

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-20
相关资源
最近更新 更多