使用TabBarIOS在React Native中创建选项卡

时间:2017-02-18 17:42:57

标签: ios react-native tabbarios

我是React的新手,并尝试关注this Tutorial。显然,它适用于旧版本的react-native。因此,当代码无效时,我会关注并调整代码。我使用ReactNative 0.41

my index.ios.js:

import React, { Component } from 'react';
import {
    AppRegistry,
    TabBarIOS
} from 'react-native';
import Featured from './Featured';
import Search from './Search';

class BookSearch extends Component {

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

    render() {
        return (
            <TabBarIOS selectedTab={this.state.selectedTab}>
                <TabBarIOS.Item
                    selected={this.state.selectedTab === 'featured'}
                    icon={{uri:'featured'}}
                    onPress={() => {
                        this.setState({
                            selectedTab: 'featured'
                        });
                    }}>
                    <Featured/>
                </TabBarIOS.Item>
                <TabBarIOS.Item
                    selected={this.state.selectedTab === 'search'}
                    icon={{uri:'search'}}
                    onPress={() => {
                        this.setState({
                            selectedTab: 'search'
                        });
                    }}>
                    <Search/>
                </TabBarIOS.Item>
            </TabBarIOS>
        );
    }
}

AppRegistry.registerComponent('BookSearch', () => BookSearch);

,这是错误:

json value'{uri =featured;}' of type NSMutableDictionary cannot be converted to an image. File not Found

2 个答案:

答案 0 :(得分:0)

我认为你输入图标的uri是错误的。变量'featured'未定义。

我可以看到有更多错误,例如您输入的selecttab错误。

干杯:)

答案 1 :(得分:0)

怀疑错误是由于语法更改造成的。新版本使用systemIcon='featured'代替icon={{uri:'featured'}}