[iPhone] UITableView strangeness

Discussion in 'Mac Programming' started by typewriter, Jun 2, 2008.

  1. typewriter macrumors newbie

    Jun 2, 2008
    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:

    - (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:

    - (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 !!
  2. tacoman667 macrumors regular

    Mar 27, 2008
    Use indexPath.row. This will get you the results you want.
  3. typewriter thread starter macrumors newbie

    Jun 2, 2008
    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..
  4. lucasgladding macrumors 6502

    Feb 16, 2007
    Waterloo, Ontario
    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.

Share This Page