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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-13-2009, 09:41 PM   #1 (permalink)
Noobieee
 
Join Date: Jan 2009
Location: silicon valley, ca
Posts: 16
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
Old 02-14-2009, 05:01 AM   #2 (permalink)
Noobieee
 
Join Date: Jan 2009
Location: silicon valley, ca
Posts: 16
Default Solved the problem

Finally got it working after searching through other threads on TableViewCell.

The codes I had below were simplified to avoid much confusion. Turns out the parts that I removed were the problem area. My bad. Should have just copied everything unabridged.

So what I had was a custom cell with several subviews that were initialized and had their contents set within ( cell == nil ) . The solution was to just initialize the cell there and assign a tag to the subview. Then outside of ( cell == nil ) I called back the subview and assign the content.

Phew....
krustaeon is offline   Reply With Quote
Reply

Bookmarks

Tags
nsarray, nsdictionary

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 259
18 members and 241 guests
14DEV, @sandris, ADY, ArtieFufkin10, ckgni, Dani77, HemiMG, IphoneSdk, jakerocheleau, JasonR, MACralik, NSeven, prchn4christ, Rudy, silverwiz, spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:54 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0