Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

typewriter

macrumors newbie
Original poster
Jun 2, 2008
2
0
Hello -

I'm writing some code for the iPhone, and have implimented a UITableView.
I have created a delegate and a dataSource. There is a strange issue however- When the table is displayed, the dataSource knows the correct *number* of cells to return, but returns duplicate copies of the 0th cell for all cells. Its behaving as if [UITableview reloadData] keeps asking cellForRowAtIndexPath for index 0.

Also, when clicking (tapping) on the cells, didSelectRowAtIndexPath only returns 0 for the tapped index.

Is this related to reuseIdentifier?

In my dataSource:

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{
	
	// Returns a formatted Table Cell
	int index=[indexPath indexAtPosition:0] ;
	printf("Creating cell for index %d\r\n",index);  //Always prints 0!

In my delegate:

Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

	printf("Index of tapped item: %d\r\n", [indexPath indexAtPosition:0]);  //Always prints 0
	
}


Thank you in advance for any help !!
 

typewriter

macrumors newbie
Original poster
Jun 2, 2008
2
0
Ahh! That solved the problem! Thank you! The weird thing is that I swear that using indexAtPosition that way *used* to work. :rolleyes:

This was a very simple answer - if only the docs had some mention of it!

The row property doesn't show up in the docs (online or local) for NSIndexPath, and it doesn't inherit that from NSObject..
 

lucasgladding

macrumors 6502
Feb 16, 2007
319
1
Waterloo, Ontario
The row property doesn't show up in the docs (online or local) for NSIndexPath, and it doesn't inherit that from NSObject..

It's a category for NSIndexPath provided by UIKit. It should be listed as NSIndexPath(UITableView). If you search the iPhone API for NSIndexPath, it should be one of two or three results.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.