[iPhone] UITableView strangeness

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

  1. typewriter macrumors newbie

    Joined:
    Jun 2, 2008
    #1
    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 !!
     
  2. tacoman667 macrumors regular

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

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

    Joined:
    Feb 16, 2007
    Location:
    Waterloo, Ontario
    #4
    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