Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 02-13-2009, 08:41 PM   #1 (permalink)
krustaeon
Noobieee
 
Join Date: Jan 2009
Location: silicon valley, ca
Posts: 16
krustaeon is on a distinguished road
Default Click-and-Hold on a tableview cell shows another cell content

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.
krustaeon is offline   Reply With Quote
 

» Advertisements
» Online Users: 460
18 members and 442 guests
7twenty7, brainspoon, dre, EmidoroSmibre, Evilelement, Hamood, iLearnColors, iOS.Lover, Kieren Harrold, kikko088, LegionMD, PavelMik, pbart, pipposanta, QuantumDoja, ryantcb, Sami Gh, waterkamp
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,615
Threads: 94,086
Posts: 402,794
Top Poster: BrianSlick (7,990)
Welcome to our newest member, PavelMik
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:06 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.