Saturday, June 8, 2013

UITableViewCell UITableViewCellAccessoryDisclosureIndicator example in Objective C (iOS).


UITableViewCell UITableViewCellAccessoryDisclosureIndicator

Cell Accessory Type
The type of standard accessory control used by a cell.

typedef enum {
UITableViewCellAccessoryNone,
UITableViewCellAccessoryDisclosureIndicator,
UITableViewCellAccessoryDetailDisclosureButton,
UITableViewCellAccessoryCheckmark
} UITableViewCellAccessoryType;

Constants
UITableViewCellAccessoryNone
The cell does not have any accessory view. This is the default value.
Available in iOS 2.0 and later.
Declared in UITableViewCell.h.
UITableViewCellAccessoryDisclosureIndicator
The cell has an accessory control shaped like a regular chevron. It is intended as a disclosure indicator. The control doesn't track touches.
UITableViewCellAccessoryDetailDisclosureButton
The cell has an accessory control that is a blue button with a chevron image as content. It is intended for configuration purposes. The control tracks touches.
UITableViewCellAccessoryCheckmark
The cell has a check mark on its right side. This control does not track touches. The delegate of the table view can manage check marks in a section of rows (possibly limiting the check mark to one row of the section) in its tableView:didSelectRowAtIndexPath: method.

Discussion of [UITableViewCell UITableViewCellAccessoryDisclosureIndicator]
You use these constants when setting the value of the accessoryType property.

UITableViewCell UITableViewCellAccessoryDisclosureIndicator example.
cell.contentView.backgroundColor=[UIColor grayColor];//or any color
cell.backgroundColor=[UIColor grayColor];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
cell.accessoryView.backgroundColor=[UIColor clearColor];

Example of [UITableViewCell UITableViewCellAccessoryDisclosureIndicator].
    if (indexPath.row==0)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    else
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

UITableViewCell UITableViewCellAccessoryDisclosureIndicator example.
It could happen because you are setting your accessory type outside of the cached cell test:

 static NSString *CellIdentifier = @"UIDocumentationCell";
     cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     if (cell == nil) {
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
     }
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
     [cell setText:mytext];
The better way, IMHO is like this:

    static NSString *CellIdentifier = @"UIDocumentationCell";
     cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     if (cell == nil) {
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
     }
     [cell setText:mytext];
Cocoa Touch doesn't seem to want to modify the cached instance of the cell ( subviews ) setting the disclosure indicator in the cell set method results in the indicator being cached, and redrawn once the cell appears again.

End of UITableViewCell UITableViewCellAccessoryDisclosureIndicator example article.