我有一个UITableView,它在加载屏幕时显示。 UITableView显示7个项目,因为dish数组包含7个项目。我有一个按钮,它增加了一个项目到菜肴阵列。
//再添加一个项目到数组 self.dishes.append(contentsOf:filteredArray)
let newIndexPath = IndexPath(row: self.dishes.count + 1, section: 0)
self.tableView.insertRows(at: [newIndexPath], with: .automatic)
添加新菜后,我收到以下错误:
'NSInternalInconsistencyException', reason: 'attempt to insert row 10 into section 0, but there are only 9 rows in section 0 after the update'
*** First throw call stack:
答案 0 :(得分:0)
我希望看到更多的代码来了解你在做什么,但我认为你应该更多这样做。
signup() {
this.setState({
// When waiting for the firebase server show the loading indicator.
loading: true
});
// Make a call to firebase to create a new user.
this.props.firebaseApp.auth().createUserWithEmailAndPassword(this.state.email, this.state.password).then((userData) => {
// then and catch are methods that we call on the Promise returned from
// createUserWithEmailAndPassword
Alert.alert('Success', 'Congrats!', [{text: 'OK!', onPress: this.dismiss}]);
this.setState({
// Clear out the fields when the user logs in and hide the progress indicator.
email: '',
password: '',
loading: false
});
AsyncStorage.setItem('userData', JSON.stringify(userData));
this.props.navigator.push({
component: Account
});
}).catch((error) => {
// Leave the fields filled when an error occurs and hide the progress indicator.
this.setState({
loading: false
});
Alert.alert('Ops', 'Error: ' + error.message, [{text: 'OK!', onPress: this.dismiss}]);
});
}
答案 1 :(得分:0)
最后一行索引是self.dishes.count而不添加1。