我有一個tableView與一些部分和每個部分有一些rows.Every行有一個最喜歡的按鈕。如果單擊該按鈕行應該被添加到收藏夾部分。 (最初是空的)。將行復制到UITableView中的另一部分
我寫了一些代碼。但問題是它在iOS 5模擬器中工作,並且在具有無效tableView更新錯誤的iOS 6模擬器中崩潰。
有人能告訴我問題在哪裏嗎?
-(void)moveRowToFavourites:(id)sender{
UIButton *button = (UIButton *)sender;
UITableViewCell *cell = (UITableViewCell *)button.superview.superview;
NSMutableArray *tempArray = [[NSMutableArray alloc] init];
[tempArray addObject:[NSIndexPath indexPathForRow:favouritesArray.count inSection:0]];
[favouritesArray insertObject:cell.textLabel.text atIndex:favouritesArray.count];
[[self tableView] beginUpdates];
[[self tableView] insertRowsAtIndexPaths:(NSArray *)tempArray withRowAnimation:UITableViewRowAnimationFade];
[[self tableView] endUpdates];
}
編輯
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(searching){
return [self.searchResults count];
}
else{
if ([[arrayForBool objectAtIndex:section] boolValue]) {
if(section == 0){
return favouritesArray.count;
}else{
NSString* key = [self.proCategoriesArray objectAtIndex:section - 1];
NSArray *aArray = [sectionContentDict valueForKey:key];
return aArray.count;
}
}
return 1;
}
}
錯誤描述包含對問題的非常明確的解釋。 –
是否嘗試reloadData而不是更新? –
錯誤是什麼? –