tags:

views:

723

answers:

3

in iphone application.

I'm trying to get indexPath.row value (out of didselectedrowatindexpath method) to do something on the basis of row selected in programmatically created tableview.

i need to access indexpath.row out of didselectedrowatindexpath method where if/else will define the action on the basis of indexpath.row.

there are 7 cards images in application and one [menu list]table view. whenever user will click on row of table view,then need to touch the image

I'm trying this code to get the IndexPath.row value. The problem is indexPath.row value is not updating everytime. It's just taking the old value. Please sugggest how to solve this issue.

- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event 
 {

    NSUInteger nSection =[myTableView numberOfSections]-1 ;
    NSUInteger nRow = [myTableView numberOfRowsInSection:nSection];    
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:nRow inSection:nSection]; 

    NSLog(@"No of sections in my table view %d",nSection);    
    NSLog(@"No of rows in my table view %d",nRow);
    NSLog(@"Value of selected indexPath Row %d", [indexPath.row]);
    NSLog(@"VAlue of Array arrOperationChk %d",[arrOperationChk count]);

 }
+1  A: 

This code appears to respond to something (the table?) being touched. You then ask the table how many rows it has in its last section and create an indexpath to that.

The table caches the number of rows in each section. If you have changed the number of rows, you need to tell the table, either by calling -insert/deleteRowsAtIndexPaths:withRowAnimation:, or by calling -reloadData. Otherwise the table has no way to know that it needs to re-query its datasource (which you provide).

Rob Napier
+1  A: 

Unless I'm reading this code wrong, aren't you just getting the index path to the last cell+1 of the last section? I wouldn't expect that to change.

If you want to get the selected cell, use the

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

method in your UITableViewController object.

kubi
A: 

As other people have said, there's nothing in your code that would change the indexPath variable you've just created.

Also, the syntax [indexPath.row] looks wrong - you don't need the square brackets there unless you're calling a method. When you use the dot syntax like that on a pointer in Objective-C, you don't think of it as a method call (even though there is one, implicitly), but rather as a pseudo-instance variable as of a struct.

What is your big picture goal? If we understood what you are trying to achieve / what is the desired behavior, maybe a more useful answer will arise.

Tyler