Saturday, June 8, 2013

UITableViewCell UITableViewCellAccessoryDetailDisclosureButton example in Objective C (iOS).


UITableViewCell UITableViewCellAccessoryDetailDisclosureButton

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 UITableViewCellAccessoryDetailDisclosureButton]
You use these constants when setting the value of the accessoryType property.

UITableViewCell UITableViewCellAccessoryDetailDisclosureButton example.
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    // Replace with your Row/cell check...
    if (indexPath.row % 2) {
        cell.accessoryType = UITableViewCellAccessoryNone;
    } else {
        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    }
}

Example of [UITableViewCell UITableViewCellAccessoryDetailDisclosureButton].
    if ([indexPath row] == [[self multas] count]) {
        [[cell textLabel] setText:@"Carregar mais..."];
    }
    else
    {
        Multa *multa = [self.multas objectAtIndex:indexPath.row];

        NSString *dataIsolada = [[NSString stringWithFormat:[multa dataOcorrencia]] substringWithRange:NSMakeRange(0, 10)];

        [[cell textLabel] setText:[NSString stringWithFormat:dataIsolada]];
        [[cell detailTextLabel] setText:[multa descricao]];
        [cell.imageView setImageWithURL:[NSURL URLWithString:[multa fotoURL]]
                       placeholderImage:[UIImage imageNamed:@"carregando.jpeg"]];
        [cell.imageView setContentMode: UIViewContentModeScaleAspectFit];
        [cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];
    }

UITableViewCell UITableViewCellAccessoryDetailDisclosureButton example.
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){

       [spinner stopAnimating];
       [self carregarDetalhesMulta:tableView comMulta:multa];
       [cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];
    });

End of UITableViewCell UITableViewCellAccessoryDetailDisclosureButton example article.