ios - 如何在React Native中使用本 map 片?

标签 ios react-native

this Tutorial 中所述,将本地存储的图像添加到 TabItem(或任何组件)会很容易:

  1. 将 XCode 中的图像添加到 images.xcassets
  2. 要求它像这样“icon={require('image!pencil')}”(图像的名称是“pencil”)

然后我得到的是 iOS 模拟器中的异常,其中包含以下文本:

Requiring unknown module "image!pencil". If you are sure the module is there, try restarting the packager

这里出了什么问题?教程?或者 React Native 已经完全改变了吗?

代码:

class devdactic_tabs extends Component {

constructor(props) {
    super(props);
    this.state = {
        selectedTab: 'welcome'
    };
}

render() {
    return (
        <TabBarIOS selectedTab={this.state.selectedTab}>
            <TabBarIOS.Item
                selected={this.state.selectedTab === 'welcome'}
                icon={require('image!pencil')}
                onPress={() => {
          this.setState({
              selectedTab: 'welcome',
          });
      }}>
                <Welcome/>
            </TabBarIOS.Item>
            <TabBarIOS.Item
                selected={this.state.selectedTab === 'more'}
                systemIcon="contacts"
                onPress={() => {
            this.setState({
                selectedTab: 'more',
            });
      }}>
                <More/>
            </TabBarIOS.Item>
        </TabBarIOS>
    );
}

}

The images-assets

最佳答案

文件名必须与 images.xcassets 中的资源名称完全相同。

例如,当您添加名为“foobar”的新图像集时,分配给该集的所有图像都必须命名为“foobar.png”。 如果您正在使用例如Glyphishpro-Images,图像文件以数字为前缀。如果您随后将这些图像重命名为不带该编号的名称,您将收到此错误!

我前几天遇到了这个问题...你也是这样吗?

关于ios - 如何在React Native中使用本 map 片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33189305/

相关文章:

android - 短信电话号码验证的替代方案 - 全局

ios - 将 UIViewcontroller 的 View 添加到 UIWindow 不显示

android - React Native Android 不包括一些内置组件和 API

ios - 找不到 React Native 模块

android - React-Native Linking.addEventListener ('url' , this._handleOpenURL);不在听

ios - UIWebView 不要弹跳和滚动

ios - 如何在 iOS 中不使用 UIImageView 的情况下在 View 上绘制/绘制 UIIMage

iphone - scrollViewWillBeginDragging 中的滚动量

android - 在 ReactNative 项目中!为什么我的 ANDROID Gradle 版本不同

github - 编译ReactAndroid,fbjni错误