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 > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-14-2010, 01:56 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 60
racharambola5 is on a distinguished road
Default Problem with UITable indexed view

Hi,

I am trying to grab the data from the database and display all the values in sorted order grouped into sections from A-Z and also my UITableView is indexed. In this case the indexes are A-Z. The strange thing that's happening is when I get all the values from the DB onto the table, I see that values under section 'B' has some values from section 'A' and if I tap on any index for example if I tap on index 'D' and come back to letter 'B' section the values that used to start with A are now replaced with D.

This happens only to section 'B' values in particular. All the values in other sections are displayed correctly. Sorry if the question is not clear. This is the best way I thought that I can describe my problem.

Please I need your help. It is very urgent to finish off this task and I can't understand why this is happening. I am a newbie in iphone development.
racharambola5 is offline   Reply With Quote
Old 08-14-2010, 02:12 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by racharambola5 View Post
Hi,

I am trying to grab the data from the database and display all the values in sorted order grouped into sections from A-Z and also my UITableView is indexed. In this case the indexes are A-Z. The strange thing that's happening is when I get all the values from the DB onto the table, I see that values under section 'B' has some values from section 'A' and if I tap on any index for example if I tap on index 'D' and come back to letter 'B' section the values that used to start with A are now replaced with D.

This happens only to section 'B' values in particular. All the values in other sections are displayed correctly. Sorry if the question is not clear. This is the best way I thought that I can describe my problem.

Please I need your help. It is very urgent to finish off this task and I can't understand why this is happening. I am a newbie in iphone development.
This kind of behavior usually means you aren't handling cell reuse correctly.

When you ask for a cell from the reuse queue, if you get a recycled cell, you have to fill out all the elements that you use. The cell will usually have values left over from the last time it was usd.

Post the code for your cellForRowAtIndexPath method, and we can take a look.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 08-14-2010, 02:19 PM   #3 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 60
racharambola5 is on a distinguished road
Default

Thanks for the reply. Here is my code



- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];;
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

if (isSearchOn) {
NSString *cellValue = [searchResult objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
} else {
NSString *contact=[contactKeys objectAtIndex:[indexPath section]];
NSArray *contactSection=[contactNames objectForKey:contact];
if (indexPath.row != 0) {
if ( [[contactSection objectAtIndex:[indexPath row]] isEqualToString:[contactSection objectAtIndex:[indexPath row]-1]] )
{
return cell;
}
else
cell.textLabel.text=[contactSection objectAtIndex:[indexPath row]];
}
else
cell.textLabel.text=[contactSection objectAtIndex:[indexPath row]];
}

return cell;
}
racharambola5 is offline   Reply With Quote
Old 08-14-2010, 02:33 PM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by racharambola5 View Post
Thanks for the reply. Here is my code



- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];;
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

if (isSearchOn) {
NSString *cellValue = [searchResult objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
} else {
NSString *contact=[contactKeys objectAtIndex:[indexPath section]];
NSArray *contactSection=[contactNames objectForKey:contact];
if (indexPath.row != 0) {
if ( [[contactSection objectAtIndex:[indexPath row]] isEqualToString:[contactSection objectAtIndex:[indexPath row]-1]] )
{
cell.textLabel.text = @"";
return cell;
}
else
cell.textLabel.text=[contactSection objectAtIndex:[indexPath row]];
}
else
cell.textLabel.text=[contactSection objectAtIndex:[indexPath row]];
}

return cell;
}
If you look at the flow of your code, there is a case where you don't set cell.textLabel.text at all. I changed the code above, assuming that in that case the text label should be nil. The change is marked in bold.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 08-14-2010, 02:49 PM   #5 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 60
racharambola5 is on a distinguished road
Default

Thanks Duncan for helping me out.. I will check with this and will let you know..
racharambola5 is offline   Reply With Quote
Old 08-14-2010, 03:02 PM   #6 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 60
racharambola5 is on a distinguished road
Default

Duncan,

By implementing the way you told me I can see empty cell on the table row whenever the above case is validated. What should I pass to get the correct value??
racharambola5 is offline   Reply With Quote
Reply

Bookmarks

Tags
indexed sections, iphone, iphone sdk, uitableview

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: 342
5 members and 337 guests
bignoggins, Chickenrig, givensur, linkmx, PlutoPrime
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,894
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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