I have spent hours trying to figure this one out. Please help.
I have a table view, grouped. When the table view first load, it is ok. Then I add a new item/cell at the last row of one of the sections and the table refreshed ok. It showed all the original cells and the new one ok.
But when I clicked-and-hold on the new cell, it overlays the cell content of the first section's first row content.
Any suggestion on where to check? I have reviewed my cellForRowAtIndexPath method and I can't seem to figure out if I did anything wrong. I may need to just take a break and review it again later but if anybody can help, I would appreciate it.
Here is parts of my code. This one is the cellForRowAtIndexPath:
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"MyTableViewCell";
UITableViewCell *myTableViewCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
TasksAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
NSDictionary *category = [appDelegate.categoryArray objectAtIndex:indexPath.section];
NSArray *contentOfCategory = [category objectForKey:@"content"];
NSDictionary *itemDetails = [contentOfCategory objectAtIndex:indexPath.row];
if (myTableViewCell == nil) {
myTableViewCell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
myTableViewCell.text = [itemDetails objectForKey:@"title"];
return myTableViewCell;
}
And this one is where I add a new item. The tableView may have a section that is empty so I check whether the content is nil or not.
Code:
- (void)addNewItem:(NSString *)title toSection:(NSInteger)section{
NSMutableDictionary *category = [categoryArray objectAtIndex:section];
NSMutableArray *contentOfCategory = [category objectForKey:@"content"];
if(contentOfCategory == nil){
contentOfCategory = [[NSMutableArray alloc] initWithObjects:nil];
[category setObject:contentOfCategory forKey:@"content"];
}
NSInteger zero = 0;
NSMutableDictionary *newItem = [NSMutableDictionary dictionaryWithObjectsAndKeys:title,@"title",zero,@"total",nil];
[contentOfCategory insertObject:newItem atIndex:[contentOfCategory count]];
}
I am thinking that maybe I am messing up the database structure when I add the new item? It should be an Array of Dictionary, which has two childs: a string and an Array. This child Array is an array of Dictionary that has multiple keys.
Thanks beforehand.