editingStyleForRowAtIndexPath called three time at the same time. Why?

I've a TableView with two UILabel for each row. When the user swipe on a cell, I would like to reduce the frame of first label on my cell, in order to fix this problem:

This is my code:

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NO] autorelease];
    }

    custom_cell = [[[UILabel alloc] initWithFrame:CGRectMake(10, 0, 200, 45)] autorelease];


    custom_cell.textColor = [UIColor blackColor];

    custom_cell.backgroundColor = [UIColor clearColor];

    [custom_cell setText:[[self.Notes objectAtIndex:indexPath.row ]objectForKey:@"Text"]];

    [cell.contentView addSubview:custom_cell];

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat: @"dd MMM yy"];

    [dateFormat setLocale:[NSLocale currentLocale]];

    NSDate *dateTmp = [[self.Notes objectAtIndex:indexPath.row] objectForKey:@"CDate"];

    cell.detailTextLabel.text = [dateFormat stringFromDate: dateTmp];

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    [dateFormat release];

    return cell;


}

Then, in order to reduce the frame of first label on my cell, I've written this code:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSLog(@"row=%d", indexPath.row);

    custom_cell.frame = CGRectMake(10, 0, 150, 45);

    return UITableViewCellEditingStyleDelete;
}

The result is partially correct. The last label of my tableView is always reduced, not the right one.

Also the console print three times the NSLog message. Why?

2012-06-13 22:07:34.809 myVoyager[1935:16103] row=0
2012-06-13 22:07:34.810 myVoyager[1935:16103] row=0
2012-06-13 22:07:34.813 myVoyager[1935:16103] row=0

Thanks, Alessandro from Pisa (sorry for my english!)

Answers


I'm Valerio from Pisa! You should do like this in your editingStyleForRowAtIndexPath method:

UITableViewCell *myCell = [self.tableView cellForRowAtIndexPath:indexPath];

and then set the frame to the cell.


Need Your Help

"A Setup Package is either missing or damaged" error while installing Visual Studio 2015 on Windows 10

visual-studio visual-studio-2015 windows-10

During the installation of Visual Studio 2015 Community on Windows 10 the following error occurred for me:

Retrieve values from array for tableview cell labels

ios xcode swift

I'm trying to retrieve values from an array and use them to populate a table view.