-1

i create a custom UITableViewCell and i add on the Cell a UIProgressView, because when i add a row on the UITableView i download the information from a XML data, and i want use the ProgressView to show the progress of the process, my question is, how i can detect in what index row i have to change the progress bar, and then hidden it?...what is the index path of the row just created?

in the:

cellForRowAtIndexPath:(NSIndexPath *)indexPath

i retrieve information from my Custom UITableViewCell in this way:

UILabel *label;

label = (UILabel *)[cell viewWithTag:1000];
label.text = [[managedObject valueForKey:@"firstName"] description];

so how i can know the index path row of the row just added, to change then the progress bar?

Piero
  • 9,173
  • 18
  • 90
  • 160
  • hey @Piero give the tag of the progressview and when you want get the value or you want to change the value of progressview fetch that view by its tag from the cell. – Leena Mar 26 '12 at 05:08
  • Ok but how i know what index have the cell? – Piero Mar 26 '12 at 07:26
  • set progressView.tag = indexPath.row and then do whatever you want to do with progressview – Leena Mar 26 '12 at 08:40

1 Answers1

0

I guess I don't understand what you are asking. indexPath is the IndexPath of the row you just created. You set a property to this value, but that property will only contain the IndexPath of the LAST row created.

Updated to show examples:

Method 1 - You aren't call the other method from within cellForRowAtIndexPath. In this case, you will need a private property of type NSIndexPath (only included code for MyViewController import and @interface declaration to show you where to put the private property declaration:

in your .m file:

#import "MyViewController.h" 

@interface MyViewController ()
    @property(nonatomic,strong) NSIndexPath *lastIndexPathCreated;
@end

@implementation MyViewController
@synthesize lastIndexPathCreated;

...

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// All your other cell setup code

self.lastIndexPathCreated = indexPath;
return cell;
}

-(void)someOtherMethod {
    // The last IndexPath of the row LAST created is self.lastIndexPathCreated
}

Method 2: This assumes you call some other method from within cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    // All your other cell setup code
    [self myOtherMethodWithIndexPath:indexPath];
    return cell;
}

-(void)myOtherMethodWithIndexPath:(NSIndexPath *)lastIndexPath {
    // Do something with lastIndexPath
}

Hope this helps

LJ Wilson
  • 14,445
  • 5
  • 38
  • 62
  • Ok so in another method in the code how i can retrive the index path of the last row just created to then use on it the tag of the progress view? – Piero Mar 26 '12 at 07:27
  • thank you very very much for the answer, but when i add a row, and load data to insert in the core data (where i retrieve the information for the row) the cellrowforindex path , reload every row in the table view, and the lastIndexPathCreated change the position in the tableview, so change also the index path... – Piero Mar 26 '12 at 09:27
  • Yes, the IndexPath will change for every row in the tableview. – LJ Wilson Mar 26 '12 at 14:25