简体   繁体   English

phonegap中iphone的原生Tab bar

[英]native Tab bar of iphone in phonegap

I want to use native tab bar of iphone using phonegap.我想使用 phonegap 使用 iphone 的本机标签栏。 I have used the code and plugin shown in http://wiki.phonegap.com/w/page/16494801/iPhone:-UIControls-%28TabBar%29 .我使用了http://wiki.phonegap.com/w/page/16494801/iPhone:-UIControls-%28TabBar%29中显示的代码和插件。 But the tab bar did not display.但是标签栏没有显示。 Can anyone help me to get tab bar in my application?谁能帮我在我的应用程序中获取标签栏?

It is quite easy.这很容易。 Normally this will not happen, because you are adding a forth parameter.通常这不会发生,因为您要添加第四个参数。

The TabBar is expecting this forth parameter or null. TabBar 期待第四个参数或 null。 But the test if this exist is buggy.但是测试是否存在是错误的。

So just put in forth dummy item --> {( foo: "bar" )} <---所以只需提出虚拟项目 --> {( foo: "bar" )} <---

plugins.tabBar.createItem("Advent Calendar", 
                          "Sven Elch", 
                          "abc.png", 
                          { foo : "bar" }  // <-----
);

or patch if condition in TabBar.m (line 334 or so).或修补 TabBar.m 中的条件(第 334 行左右)。

if(options != [NSNull null])
{
    id badgeOpt = [options objectForKey:@"badge"];

    if(badgeOpt && badgeOpt != [NSNull null])
        item.badgeValue = [badgeOpt stringValue];
}

Steps (might be the same for any plugin):步骤(任何插件都可能相同):

  • Get the plugin iOS NativeControls获取插件iOS NativeControls
  • Copy *.xib, *.m and *.h files to your project's "Plugins" folder (should already exist and contain a README file)将 *.xib、*.m 和 *.h 文件复制到项目的“插件”文件夹(应该已经存在并包含 README 文件)
  • They have to be added to the project as well, so drag them from the "Plugins" folder (in Finder) to the same folder (in Xcode) and select to create references它们也必须添加到项目中,因此将它们从“插件”文件夹(在 Finder 中)拖到同一文件夹(在 Xcode 中)和 select 以创建引用
  • Open "Resources/Cordova.plist" and under "Plugins", add a key with the plugin name "NativeControls" and a string value of "NativeControls" (I guess it's the plugin's main class name)打开“Resources/Cordova.plist”并在“Plugins”下,添加一个插件名称为“NativeControls”和字符串值为“NativeControls”的键(我猜它是插件的主要 class 名称)
  • Try the following example ( NOTE: this example is from 2012-06-28, I'm actually working on an improved version that removes the toolbar functionality and replaces it with an actually working navigation bar – see here )试试下面的例子(注意:这个例子来自 2012 年 6 月 28 日,我实际上正在开发一个改进的版本,它删除了工具栏功能并将其替换为一个实际工作的导航栏——见这里

     window.plugins.nativeControls.createTabBar() window.plugins.nativeControls.createTabBarItem('home', 'Home', 'tabButton:Contacts') window.plugins.nativeControls.showTabBar() window.plugins.nativeControls.showTabBarItems('home') window.plugins.nativeControls.createToolBar() window.plugins.nativeControls.setToolBarTitle('Hello toolbar.') window.plugins.nativeControls.showToolBar() alert("Tabs and toolbar should now become visible")

I can't get the title of the toolbar to work, though, but both the tab and the toolbar itself (without text) is showing.但是,我无法让工具栏的标题正常工作,但选项卡和工具栏本身(没有文本)都在显示。

I believe that plugin got deprecated.我相信该插件已被弃用。 Go to http://github.com/phonegap/phonegap-plugins/ . Go 到http://github.com/phonegap/phonegap-plugins/ In there you will see a plugin called native control under iPhone.在那里,您将看到一个名为 iPhone 下的原生控件的插件。 That is the plugin you want to use.那就是您要使用的插件。

After you download it, add the nativecontrols files to your plugin folder in your project.下载后,将 nativecontrols 文件添加到项目中的插件文件夹中。 Add NativeControls as a key and value in phonegap.plist file.在 phonegap.plist 文件中添加 NativeControls 作为键和值。 Add the nativecontrols js file to your www directory.将 nativecontrols js 文件添加到您的 www 目录。 Then you can create, show, etc your tabbar然后你可以创建、显示等你的标签栏

Just try this:试试这个:

<script>
    var moreNum = 1;
    plugins.nativeControls.createToolBar();
    plugins.nativeControls.setToolBarTitle("hello");

    plugins.nativeControls.createTabBar();  
    plugins.nativeControls.createTabBarItem("search","search","tabButton:Search");
    plugins.nativeControls.createTabBarItem("book","book","tabButton:Contacts");
    plugins.nativeControls.createTabBarItem("more","more","tabButton:More",{"onSelect":function(){
                                            plugins.nativeControls.updateTabBarItem("more",{"badge":((++moreNum).toString())});
                                            }});
    plugins.nativeControls.showTabBar();
    plugins.nativeControls.showTabBarItems("book","search","more");
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM