每次退出此xib并返回时,我都会收到重复的单元格。
假设我添加了两种成分,米饭和糖。如果我退出并返回,我有两倍的成分。每次加载此控制器时都会发生这种情况。
我认为这是错误的代码:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
//fixed doubling up of ingredients by addingn else before the other if and corresponding bracket Nov 13 falcon
if (self.groceryList) {
self.arrIngredients = [((MealIdeaAppDelegate*)MI_SHARED_DELEGATE).dbCommunicator getMyGroceryListIngredients:self.groceryList.groceryListID];
NSLog(@"data %@ ",self.groceryList.groceryListID);
self.title = self.groceryList.groceryListName;
txtfListName.text = self.groceryList.groceryListName;
//Added else Nov 13 falcon
}else if ([self.groceryList.groceryListName caseInsensitiveCompare:kDeafaultGroceryListName] == 0) {
[txtfListName setUserInteractionEnabled:NO];
}
[tblvGroceryListDetail reloadData];
}
答案 0 :(得分:1)
我认为问题在于你已经将值添加到数组中,当你退出并返回时,再次调用viewWillAppear:再次向数组添加相同的数据,因此加倍数据,为此你应该这样做viewDidLoad:method
中的代码 -(void)viewDidLoad:(BOOL)animated
{
// do the code done in viewWillAppear here
}