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 {
} UITableViewCellAccessoryType;

The cell does not have any accessory view. This is the default value.
Available in iOS 2.0 and later.
Declared in UITableViewCell.h.
The cell has an accessory control shaped like a regular chevron. It is intended as a disclosure indicator. The control doesn't track touches.
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.
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..."];
        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.