Saturday, June 8, 2013

UITableViewCell UITableViewCellAccessoryCheckmark example in Objective C (iOS).


UITableViewCell UITableViewCellAccessoryCheckmark

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

UITableViewCell UITableViewCellAccessoryCheckmark example.
   UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastindex];
    if (oldCell.accessoryType == UITableViewCellAccessoryCheckmark);
    {  
        oldCell.accessoryType = UITableViewCellAccessoryNone;  
    } else{

           UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];    

            if (newCell.accessoryType == UITableViewCellAccessoryNone)
              {  
               newCell.accessoryType = UITableViewCellAccessoryCheckmark; 
              } 
    }

Example of [UITableViewCell UITableViewCellAccessoryCheckmark].
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    for (id algoPath in [tableView indexPathsForVisibleRows]){
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:algoPath];
    cell.accessoryType = UITableViewCellAccessoryNone;

    if(algoPath == indexPath){
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
}

UITableViewCell UITableViewCellAccessoryCheckmark example.
    if (newRow != oldRow)
    {
     UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
     newCell.accessoryType = UITableViewCellAccessoryCheckmark;

     UITableViewCell *oldCell = [tableView cellForRowAtIndexPath: lastIndexPath];
     oldCell.accessoryType = UITableViewCellAccessoryNone;

     lastIndexPath = indexPath;
    }
    else
    {
     UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
     newCell.accessoryType = UITableViewCellAccessoryCheckmark;
     lastIndexPath = indexPath;
    }

End of UITableViewCell UITableViewCellAccessoryCheckmark example article.