Saturday, June 8, 2013

UITableViewCell setEditingAccessoryType example in Objective C (iOS).


UITableViewCell setEditingAccessoryType

The type of standard accessory view the cell should use in the table view’s editing state.

@property(nonatomic) UITableViewCellAccessoryType editingAccessoryType

Discussion of [UITableViewCell setEditingAccessoryType]
The accessory view appears in the right side of the cell when the table view is in editing mode. The standard accessory views include the disclosure chevron; for a description of valid constants, see “Cell Accessory Type.” The default is UITableViewCellAccessoryNone. If a custom accessory view for editing mode is set through the editingAccessoryView property, the value of this property is ignored. If the cell is enabled and the accessory type is UITableViewCellAccessoryDetailDisclosureButton, the accessory view tracks touches and, when tapped, sends the delegate object a tableView:accessoryButtonTappedForRowWithIndexPath: message.[UITableViewCell setEditingAccessoryType]

The accessory type cross-fades between normal and editing states if it set for both states; use the accessoryType property to set the accessory view for the cell during the table view’s normal state. If this property is not set for both states, the cell is animated to slide or out, as necessary.

UITableViewCell setEditingAccessoryType example.
Since hidesAccessoryWhenEditing was deprecated in 3.0, use the UITableViewCell's editingAccessoryType property like so:

[cell setEditingAccessoryType:UITableViewCellAccessoryCheckmark]; or cell.editingAccessoryType = UITableViewCellAccessoryCheckmark;

or the appropriate accessory type to suit your needs.


Example of [UITableViewCell setEditingAccessoryType].
            switch (row)
            {
                case CATEGORY_ROW:
                    text                        = [self.purchase.category valueForKey:@"name"];
                    cell.textLabel.text         = text;
                    cell.accessoryType          = UITableViewCellAccessoryNone;
                    cell.editingAccessoryType   = UITableViewCellAccessoryDisclosureIndicator;
                    break;
                case TYPE_ROW:
                    text                        = [self.purchase.type valueForKey:@"name"];
                    cell.textLabel.text         = text;
                    cell.accessoryType          = UITableViewCellAccessoryNone;
                    cell.editingAccessoryType   = UITableViewCellAccessoryDisclosureIndicator;
                    break;
                case VENDOR_ROW:
                    text                        = [self.purchase.vendor valueForKey:@"name"];
                    cell.textLabel.text         = text;
                    cell.accessoryType          = UITableViewCellAccessoryNone;
                    cell.editingAccessoryType   = UITableViewCellAccessoryDisclosureIndicator;
                    break;
                case NOTES_ROW:
                    text                        = @"Notes";
                    cell.textLabel.text         = text;
                    cell.accessoryType          = UITableViewCellAccessoryNone;
                    cell.editingAccessoryType   = UITableViewCellAccessoryDisclosureIndicator;
                    break;
                default:
                    break;
            }
            break;
 

UITableViewCell setEditingAccessoryType example.
{

                    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

                   

                    if (cell == nil) {

                         cell = [[[UITableViewCell alloc ] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier] autorelease];

                    }

                    cell.textLabel.font =[UIFont boldSystemFontOfSize:15.0];

                    cell.textLabel.textColor = [UIColor blackColor];

                    cell.editingAccessoryType = UITableViewCellAccessoryNone;

                    cell.textLabel.text = [NSString stringWithFormat:@\"%@ (%@)\",[[[partnershipToEdit children] objectAtIndex:indexPath.row] fullname], [[[partnershipToEdit children] objectAtIndex:indexPath.row] sex]];

                    break;

               }

End of UITableViewCell setEditingAccessoryType example article.