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 12-15-2009, 02:29 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 5
Default CellForRowAtIndexPath scrolling issue

Hi everyone,
I am having problems with a tableView in a project I am working on. The data loads into the table perfectly at first, but when I scroll to see the remaining data, the NSMutableArray that I am using has the correct number of elements, however it is filled with invalid data (its an array of objects).

Heres how I define the array in the view controller's .h file:
Code:
NSMutableArray *appts;
and
Code:
@property (nonatomic, retain) NSMutableArray *appts;
in viewDidLoad I am populating the array from a method that returns NSMutableArray:
Code:
self.appts = [dbTran selectAppointments:[NSDate date]];
In cellForRowAtIndexPath I am getting the data from the array:
Code:
Appointments *appt = (Appointments *)[self.appts objectAtIndex:indexPath.row];
If I set a breakpoint on the code in cellForRowAtIndexPath, i can see that the appts array has 9 objects, but the properties are invalid for every object.
What am I doing wrong?

I appreciate the help!

Thanks
agnos5 is offline   Reply With Quote
Old 12-15-2009, 02:52 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

Too many variables to answer the question.

In what way is the data invalid? Is the data itself incorrect, or is what you see in the table incorrect?
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 12-15-2009, 03:06 PM   #3 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 5
Default

Quote:
Originally Posted by BrianSlick View Post
Too many variables to answer the question.

In what way is the data invalid? Is the data itself incorrect, or is what you see in the table incorrect?
I agree. Too many things can go wrong. I tried to be as generic as I can.

after scrolling up when debugging with a breakpoint set, I can see that the array has the correct number of elements, and they are all Appointments objects, but the object's properties are invalid. not blank, nill or any other real value. Its like the object is there, but its not initialized.

Initially, when the tableView loads, the data shows perfectly, and I am able to push to a detail view as well.

Last edited by agnos5; 12-15-2009 at 03:11 PM. Reason: clarity
agnos5 is offline   Reply With Quote
Old 12-15-2009, 03:12 PM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

Post your cellForRow code.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 12-15-2009, 03:21 PM   #5 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 5
Default

Quote:
Originally Posted by BrianSlick View Post
Post your cellForRow code.
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
	static NSString *CellIdentifier = @"Cell";
	
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
	
	if(cell == nil)
		cell = [self getCellContentView:CellIdentifier];
	
	UILabel *lblTemp1 = (UILabel *)[cell viewWithTag:1];
	UILabel *lblTemp2 = (UILabel *)[cell viewWithTag:2];
	
	Appointments *appt = (Appointments *)[self.appts objectAtIndex:indexPath.row];
	NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

	DBTransaction *dbTran = [DBTransaction alloc];
	[dbTran initWithUserName:@"iphone"];

	Customer *customer = [dbTran getNameById:appt.Id];
	lblTemp1.text = [appt.Id stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
	lblTemp2.text = customer.name;
	
	cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

	return cell;
}
agnos5 is offline   Reply With Quote
Old 12-15-2009, 03:25 PM   #6 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

If the initial display is correct, that suggests the issue is with getCellContentView.

However, add some log messages to make sure that each of your various data elements is correct before assigning them to the labels.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 12-15-2009, 03:41 PM   #7 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 5
Default

Quote:
Originally Posted by BrianSlick View Post
If the initial display is correct, that suggests the issue is with getCellContentView.

However, add some log messages to make sure that each of your various data elements is correct before assigning them to the labels.
getCellContentView is not the problem, i am simply adding labels to the contentView of the cells to display the data. I can post that if you like, but theres nothing else involved.


Any other thoughts?

Thanks
agnos5 is offline   Reply With Quote
Old 12-15-2009, 03:46 PM   #8 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

Well, you either have a data problem or a display problem.

If it is a data problem, log messages should help to reveal that. Add them and see what they say.

If it is a display problem, the only atypical thing I see here is getCellContentView. I'd be curious to see what you're doing there, since the name sounds awkward. Cell vs. content view is an important distinction.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Reply

Bookmarks

Tags
nsmutablearray, scrolling, 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: 231
16 members and 215 guests
ADY, Alsahir, cacao, dacapo, Dani77, Desert Diva, djohnson, F_Bryant, HemiMG, jansan, M@realobjects, MarkC, prchn4christ, smethorst, spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,228
Posts: 380,762
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

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