Showing posts with label UITableViewCell. Show all posts
Showing posts with label UITableViewCell. Show all posts

Saturday, June 8, 2013

UITableViewCell UITableViewCellSeparatorStyleSingleLine example in Objective C (iOS).


UITableViewCell UITableViewCellSeparatorStyleSingleLine

Cell Separator Style
The style for cells used as separators.

typedef enum {
UITableViewCellSeparatorStyleNone,
UITableViewCellSeparatorStyleSingleLine,
UITableViewCellSeparatorStyleSingleLineEtched
} UITableViewCellSeparatorStyle;

Constants
UITableViewCellSeparatorStyleNone
The separator cell has no distinct style.
UITableViewCellSeparatorStyleSingleLine
The separator cell has a single line running across its width. This is the default value
UITableViewCellSeparatorStyleSingleLineEtched
The separator cell has double lines running across its width, giving it an etched look. This style is currently only supported for grouped-style table views.

Discussion of [UITableViewCell UITableViewCellSeparatorStyleSingleLine]
You use these constants to set the value of the separatorStyle property defined by UITableView.

UITableViewCell UITableViewCellSeparatorStyleSingleLine example.
  [TableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];

  [TableView setSeparatorColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Divider_line@2x.png"]]];

Example of [UITableViewCell UITableViewCellSeparatorStyleSingleLine].
if ([[self.fetchedResultsController fetchedObjects] count] == 0)
{
    self.routineTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.routineTableView.separatorColor = [UIColor clearColor];
}
else
{
     self.routineTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; // or you have the previous 'None' style...
    self.routineTableView.separatorColor = [UIColor grayColor];
}

UITableViewCell UITableViewCellSeparatorStyleSingleLine example.
static NSString *cellIdentifier = @"cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

if(cell == nil)
{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellSeparatorStyleSingleLine reuseIdentifier:cellIdentifier] autorelease];
}

End of UITableViewCell UITableViewCellSeparatorStyleSingleLine example article.

UITableViewCell UITableViewCellStateShowingEditControlMask example in Objective C (iOS).


UITableViewCell UITableViewCellStateShowingEditControlMask

Cell State Mask Constants
Constants used to determine the new state of a cell as it transitions between states.

enum {
UITableViewCellStateDefaultMask = 0,
UITableViewCellStateShowingEditControlMask = 1 << 0,
UITableViewCellStateShowingDeleteConfirmationMask = 1 << 1
};

Constants
UITableViewCellStateDefaultMask
The normal state of a table cell.
UITableViewCellStateShowingEditControlMask
The state of a table view cell when the table view is in editing mode.
UITableViewCellStateShowingDeleteConfirmationMask
The state of a table view cell that shows a button requesting confirmation of a delete gesture.

Discussion of [UITableViewCell UITableViewCellStateShowingEditControlMask]
The methods that use these constants are didTransitionToState: and willTransitionToState:.

UITableViewCell UITableViewCellStateShowingEditControlMask example.
- (void)willTransitionToState:(UITableViewCellStateMask)state
{
    NSString *logStr = @"Invoked";
    if ((state & UITableViewCellStateShowingEditControlMask)
        != 0) {
        // you need to move the controls in left
        logStr = [NSString stringWithFormat:@"%@
                  %@",logStr,@"UITableViewCellStateShowingEditControlMask"];
    }
    if ((state & UITableViewCellStateShowingDeleteConfirmationMask)
        != 0) {
        // you need to hide the controls for the delete button
        logStr = [NSString stringWithFormat:@"%@
                  %@",logStr,@"UITableViewCellStateShowingDeleteConfirmationMask"];
    }
    NSLog(@"%@",logStr);
    [super willTransitionToState:state];
}

Example of [UITableViewCell UITableViewCellStateShowingEditControlMask].
- (void)layoutSubviews
{
    [super layoutSubviews];

    self.contentView.frame = CGRectMake(0,                                         
                                        self.contentView.frame.origin.y,
                                        self.contentView.frame.size.width,
                                        self.contentView.frame.size.height);

    if (self.editing
        && ((state & UITableViewCellStateShowingEditControlMask)
        && !(state & UITableViewCellStateShowingDeleteConfirmationMask)) ||
            ((state & UITableViewCellStateShowingEditControlMask)
         && (state & UITableViewCellStateShowingDeleteConfirmationMask)))
    {
        float indentPoints = self.indentationLevel * self.indentationWidth;

        self.contentView.frame = CGRectMake(indentPoints,
                                            self.contentView.frame.origin.y,
                                            self.contentView.frame.size.width - indentPoints,
                                            self.contentView.frame.size.height);   
    }
}

UITableViewCell UITableViewCellStateShowingEditControlMask example.
- (void)willTransitionToState:(UITableViewCellStateMask)state {

    [super willTransitionToState:state];

    if (state == UITableViewCellStateDefaultMask) {

        NSLog(@"Default");
        // When the cell returns to normal (not editing)
        // Do something...

    } else if ((state & UITableViewCellStateShowingEditControlMask) && (state & UITableViewCellStateShowingDeleteConfirmationMask)) {

        NSLog(@"Edit Control + Delete Button");
        // When the cell goes from Showing-the-Edit-Control (-) to Showing-the-Edit-Control (-) AND the Delete Button [Delete]
        // !!! It's important to have this BEFORE just showing the Edit Control because the edit control applies to both cases.!!!
        // Do something...

    } else if (state & UITableViewCellStateShowingEditControlMask) {

        NSLog(@"Edit Control Only");
        // When the cell goes into edit mode and Shows-the-Edit-Control (-)
        // Do something...

    } else if (state == UITableViewCellStateShowingDeleteConfirmationMask) {

        NSLog(@"Swipe to Delete [Delete] button only");
        // When the user swipes a row to delete without using the edit button.
        // Do something...
    }
}

End of UITableViewCell UITableViewCellStateShowingEditControlMask example article.

UITableViewCell UITableViewCellStateDefaultMask example in Objective C (iOS).


UITableViewCell UITableViewCellStateDefaultMask

Cell State Mask Constants
Constants used to determine the new state of a cell as it transitions between states.

enum {
UITableViewCellStateDefaultMask = 0,
UITableViewCellStateShowingEditControlMask = 1 << 0,
UITableViewCellStateShowingDeleteConfirmationMask = 1 << 1
};

Constants
UITableViewCellStateDefaultMask
The normal state of a table cell.
UITableViewCellStateShowingEditControlMask
The state of a table view cell when the table view is in editing mode.
UITableViewCellStateShowingDeleteConfirmationMask
The state of a table view cell that shows a button requesting confirmation of a delete gesture.

Discussion of [UITableViewCell UITableViewCellStateDefaultMask]
The methods that use these constants are didTransitionToState: and willTransitionToState:.

UITableViewCell UITableViewCellStateDefaultMask example.
- (void)willTransitionToState:(UITableViewCellStateMask)state {
    if (state == UITableViewCellStateDefaultMask) {
        // User has switched back to default state...
        // ...
    }
}

Example of [UITableViewCell UITableViewCellStateDefaultMask].
- (void)didTransitionToState:(UITableViewCellStateMask)state {

    [super didTransitionToState:state];

    if (state == UITableViewCellStateShowingDeleteConfirmationMask || state == UITableViewCellStateDefaultMask) {
        for (UIView *subview in self.subviews) {

            if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {

                UIView *deleteButtonView = (UIView *)[subview.subviews objectAtIndex:0];
                CGRect f = deleteButtonView.frame;
                f.origin.x -= 20;
                deleteButtonView.frame = f;

                subview.hidden = NO;

                [UIView beginAnimations:@"anim" context:nil];
                subview.alpha = 1.0;
                [UIView commitAnimations];
            }
        }
    }
}

UITableViewCell UITableViewCellStateDefaultMask example.
- (void)willTransitionToState:(UITableViewCellStateMask)state {

    [super willTransitionToState:state];

    if (state == UITableViewCellStateDefaultMask) {

        NSLog(@"Default");
        // When the cell returns to normal (not editing)
        // Do something...

    } else if ((state & UITableViewCellStateShowingEditControlMask) && (state & UITableViewCellStateShowingDeleteConfirmationMask)) {

        NSLog(@"Edit Control + Delete Button");
        // When the cell goes from Showing-the-Edit-Control (-) to Showing-the-Edit-Control (-) AND the Delete Button [Delete]
        // !!! It's important to have this BEFORE just showing the Edit Control because the edit control applies to both cases.!!!
        // Do something...

    } else if (state & UITableViewCellStateShowingEditControlMask) {

        NSLog(@"Edit Control Only");
        // When the cell goes into edit mode and Shows-the-Edit-Control (-)
        // Do something...

    } else if (state == UITableViewCellStateShowingDeleteConfirmationMask) {

        NSLog(@"Swipe to Delete [Delete] button only");
        // When the user swipes a row to delete without using the edit button.
        // Do something...
    }
}

End of UITableViewCell UITableViewCellStateDefaultMask example article.

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.

UITableViewCell UITableViewCellEditingStyleNone example in Objective C (iOS).


UITableViewCell UITableViewCellEditingStyleNone

Cell Editing Style
The editing control used by a cell.

typedef enum {
UITableViewCellEditingStyleNone,
UITableViewCellEditingStyleDelete,
UITableViewCellEditingStyleInsert
} UITableViewCellEditingStyle;

Constants
UITableViewCellEditingStyleNone
The cell has no editing control. This is the default value.
UITableViewCellEditingStyleDelete
The cell has the delete editing control; this control is a red circle enclosing a minus sign.
UITableViewCellEditingStyleInsert
The cell has the insert editing control; this control is a green circle enclosing a plus sign.

Discussion of [UITableViewCell UITableViewCellEditingStyleNone]
You use them to set the value of the editingStyle property.

UITableViewCell UITableViewCellEditingStyleNone example.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewCellEditingStyleNone;
}
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{

}

Example of [UITableViewCell UITableViewCellEditingStyleNone].
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

if (selectionPath.row == indexPath.row)
    {
        return UITableViewCellEditingStyleDelete;
    }
    else
    {
        return UITableViewCellEditingStyleNone;    
    }
}

UITableViewCell UITableViewCellEditingStyleNone example.
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
// No editing style if not editing or the index path is nil.
if (!indexPath) return UITableViewCellEditingStyleNone;

// No editing style if the tableView has no cells.
if ([self.array count] == 0) return UITableViewCellEditingStyleNone;

// If tableView is not editing, then return delete button.
if (tableView.editing == NO) return UITableViewCellEditingStyleDelete;

// If tableView is editing, then return delete button too.
if (tableView.editing == YES) return UITableViewCellEditingStyleDelete;

// If none of the above are returned, then return \"none\".
return UITableViewCellEditingStyleNone;
}

End of UITableViewCell UITableViewCellEditingStyleNone example article.

UITableViewCell UITableViewCellStyleValue2 example in Objective C (iOS).


UITableViewCell UITableViewCellStyleValue2

Cell Styles
An enumeration for the various styles of cells.

typedef enum {
UITableViewCellStyleDefault,
UITableViewCellStyleValue1,
UITableViewCellStyleValue2,
UITableViewCellStyleSubtitle
} UITableViewCellStyle;

Constants
UITableViewCellStyleDefault
A simple style for a cell with a text label (black and left-aligned) and an optional image view. Note that this is the default style for cells prior to iOS 3.0.
UITableViewCellStyleValue1
A style for a cell with a label on the left side of the cell with left-aligned and black text; on the right side is a label that has smaller blue text and is right-aligned. The Settings application uses cells in this style.
UITableViewCellStyleValue2
A style for a cell with a label on the left side of the cell with text that is right-aligned and blue; on the right side of the cell is another label with smaller text that is left-aligned and black. The Phone/Contacts application uses cells in this style.
UITableViewCellStyleSubtitle
A style for a cell with a left-aligned label across the top and a left-aligned label below it in smaller gray text. The iPod application uses cells in this style.

Discussion of [UITableViewCell UITableViewCellStyleValue2]
In all these cell styles, the larger of the text labels is accessed via the textLabel property and the smaller via the detailTextLabel property.

UITableViewCell UITableViewCellStyleValue2 example.
UITableViewCellStyleSubtitle:

textLabel: Helvetica Bold, size: labelFontSize+1 (18 px)

detailsLabel: Helvetica, size: systemFontSize (14 px)

UITableViewCellStyleValue1:

textLabel: Helvetica Bold, size: labelFontSize (17 px)

detailsLabel: Helvetica Bold, size: systemFontSize+1 (15 px)

UITableViewCellStyleValue2:

textLabel: Helvetica Bold, size: smallSystemFontSize (12 px)

detailsLabel: Helvetica, size: labelFontSize (17 px)

Example of [UITableViewCell UITableViewCellStyleValue2].
            if (cell == nil) {
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
            }
            NSDictionary *item = [tableData objectAtIndex:(indexRow-cellShift)];
            NSString *name = [item objectForKey:@"Name"];
            if ([name length] > MaxVendorsLength ) {
                name =  [NSString stringWithFormat:@"%@ ...",[name substringToIndex:MaxVendorsLength]];
            }
            cell.textLabel.text = name;
            cell.textLabel.minimumFontSize = 12;

UITableViewCell UITableViewCellStyleValue2 example.
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell.
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

End of UITableViewCell UITableViewCellStyleValue2 example article.

UITableViewCell UITableViewCellStyleValue1 example in Objective C (iOS).


UITableViewCell UITableViewCellStyleValue1

Cell Styles
An enumeration for the various styles of cells.

typedef enum {
UITableViewCellStyleDefault,
UITableViewCellStyleValue1,
UITableViewCellStyleValue2,
UITableViewCellStyleSubtitle
} UITableViewCellStyle;

Constants
UITableViewCellStyleDefault
A simple style for a cell with a text label (black and left-aligned) and an optional image view. Note that this is the default style for cells prior to iOS 3.0.
UITableViewCellStyleValue1
A style for a cell with a label on the left side of the cell with left-aligned and black text; on the right side is a label that has smaller blue text and is right-aligned. The Settings application uses cells in this style.
UITableViewCellStyleValue2
A style for a cell with a label on the left side of the cell with text that is right-aligned and blue; on the right side of the cell is another label with smaller text that is left-aligned and black. The Phone/Contacts application uses cells in this style.
UITableViewCellStyleSubtitle
A style for a cell with a left-aligned label across the top and a left-aligned label below it in smaller gray text. The iPod application uses cells in this style.

Discussion of [UITableViewCell UITableViewCellStyleValue1]
In all these cell styles, the larger of the text labels is accessed via the textLabel property and the smaller via the detailTextLabel property.

UITableViewCell UITableViewCellStyleValue1 example.
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];

}

cell.textLabel.lineBreakMode = UILineBreakModeTailTruncation;

Example of [UITableViewCell UITableViewCellStyleValue1].
            if (cell == nil) {
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
            }
            NSDictionary *item = [tableData objectAtIndex:(indexRow-cellShift)];
            NSString *name = [item objectForKey:@"Name"];
            if ([name length] > MaxVendorsLength ) {
                name =  [NSString stringWithFormat:@"%@ ...",[name substringToIndex:MaxVendorsLength]];
            }
            cell.textLabel.text = name;
            cell.textLabel.minimumFontSize = 12;

UITableViewCell UITableViewCellStyleValue1 example.
    static NSString *CellIdentifier = @"Cell";

    UILabel *label;

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] ;
    }

    label = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 280, 34)];

    [label setNumberOfLines:2];

    label.backgroundColor = [UIColor clearColor];

    [label setFont:[UIFont systemFontOfSize:FONT_SIZE]];

    label.adjustsFontSizeToFitWidth = NO;

    [[cell contentView] addSubview:label];

End of UITableViewCell UITableViewCellStyleValue1 example article.

UITableViewCell willTransitionToState example in Objective C (iOS).


UITableViewCell willTransitionToState

Called on the cell just before it transitions between cell states.

- (void)willTransitionToState:(UITableViewCellStateMask)state

Parameters of [UITableViewCell willTransitionToState]
state
A bit mask indicating the state or combination of states the cell is transitioning to.

Discussion of [UITableViewCell willTransitionToState]
Subclasses of UITableViewCell can implement this method to animate additional changes to a cell when it is changing state. UITableViewCell calls this method whenever a cell transitions between states, such as from a normal state (the default) to editing mode. The custom cell can set up and position any new views that appear with the new state. The cell then receives a layoutSubviews message (UIView) in which it can position these new views in their final locations for the new state. Subclasses must always call super when overriding this method.

Note that when the user swipes a cell to delete it, the cell transitions to the state identified by the UITableViewCellStateShowingDeleteConfirmationMask constant but the UITableViewCellStateShowingEditControlMask is not set.

UITableViewCell willTransitionToState example.
- (void)willTransitionToState:(UITableViewCellStateMask)state
{
    NSString *logStr = @"Invoked";
    if ((state & UITableViewCellStateShowingEditControlMask)
        != 0) {
        // you need to move the controls in left
        logStr = [NSString stringWithFormat:@"%@
                  %@",logStr,@"UITableViewCellStateShowingEditControlMask"];
    }
    if ((state & UITableViewCellStateShowingDeleteConfirmationMask)
        != 0) {
        // you need to hide the controls for the delete button
        logStr = [NSString stringWithFormat:@"%@
                  %@",logStr,@"UITableViewCellStateShowingDeleteConfirmationMask"];
    }
    NSLog(@"%@",logStr);
    [super willTransitionToState:state];
}

Example of [UITableViewCell willTransitionToState].
- (void)willTransitionToState:(UITableViewCellStateMask)state {

    [super willTransitionToState:state];

    if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) {

        for (UIView *subview in self.subviews) {

            if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {            

                subview.hidden = YES;
                subview.alpha = 0.0;
            }
        }
    }
}

UITableViewCell willTransitionToState example.
- (void)willTransitionToState:(UITableViewCellStateMask)state
{
    if (state == UITableViewCellStateShowingDeleteConfirmationMask) {
        swipedToDelete = YES; // BOOL ivar
    }
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    if (swipedToDelete) {
        // do your stuff, or don't
    }
}

End of UITableViewCell willTransitionToState example article.

UITableViewCell setHighlighted animated example in Objective C (iOS).


UITableViewCell setHighlighted animated

Sets the highlighted state of the cell, optionally animating the transition between states.

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated

Parameters of [UITableViewCell setHighlighted animated]
highlighted
YES to set the cell as highlighted, NO to set it as unhighlighted. The default is NO.
animated
YES to animate the transition between highlighted states, NO to make the transition immediate.

Discussion of [UITableViewCell setHighlighted animated]
Highlights or unhighlights the cell, animating the transition between regular and highlighted state if animated is YES. Highlighting affects the appearance of the cell’s labels, image, and background.

Note that for highlighting to work properly, you must fetch the cell’s label (or labels) using the textLabel (and detailTextLabel properties and set the label’s highlightedTextColor property; for images, get the cell’s image using the imageView property and set the UIImageView object’s highlightedImage property.[UITableViewCell setHighlighted animated]

A custom table cell may override this method to make any transitory appearance changes.

UITableViewCell setHighlighted animated example.
// animate between regular and highlighted state
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated; {
    [super setHighlighted:highlighted animated:animated];

    //Set the correct background Image
    UIImageView* backgroundPicture = (UIImageView*)[self viewWithTag:HACK_BACKGROUND_VIEW_TAG];
    if (highlighted) {
        backgroundPicture.image = [UIImage imageNamed:@"FondSelected.png"];
    }
    else {
        backgroundPicture.image = [UIImage imageNamed:@"Fond.png"];
    }
}

Example of [UITableViewCell setHighlighted animated].
- (void)updateCellDisplay {
    if (self.selected || self.highlighted) {
        self.nameLabel.textColor = [UIColor lightGrayColor];
        self.colorLabel.textColor = [UIColor lightGrayColor];
    }
    else {
        self.nameLabel.textColor = [UIColor blackColor];
        self.colorLabel.textColor = [UIColor blackColor];
    }
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
    [super setHighlighted:highlighted animated:animated];
    [self updateCellDisplay];
}

- (void) setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    [self updateCellDisplay];
}

UITableViewCell setHighlighted animated example.
You must also override setHighlighted: to prevent the blue gradient from ever showing. If you just override setHighlighted: then you end up with a momentary selection effect.

so you'll have these two methods:

- (void)setHighlighted: (BOOL)highlighted animated: (BOOL)animated
{
    // don't highlight
}

- (void)setSelected: (BOOL)selected animated: (BOOL)animated
{
    // don't select
    //[super setSelected:selected animated:animated];
}

End of UITableViewCell setHighlighted animated example article.

UITableViewCell setEditing animated example in Objective C (iOS).


UITableViewCell setEditing animated

Toggles the receiver into and out of editing mode.

- (void)setEditing:(BOOL)editing animated:(BOOL)animated

Parameters
editing
YES to enter editing mode, NO to leave it. The default value is NO .
animated
YES to animate the appearance or disappearance of the insertion/deletion control and the reordering control, NO to make the transition immediate.

Discussion of [UITableViewCell setEditing animated]
When you call this method with the value of editing set to YES, and the UITableViewCell object is configured to have controls, the cell shows an insertion (green plus) or deletion control (red minus) on the left side of each cell and a reordering control on the right side. This method is called on each visible cell when the setEditing:animated: method of UITableView is invoked. Calling this method with editing set to NO removes the controls from the cell.

UITableViewCell setEditing animated example.
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"My View Controller";
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editButtonSelected:)] autorelease];

}

- (void) editButtonSelected: (id) sender
{
    if (tableView1.editing) {
        self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editButtonSelected:)] autorelease];
        [self.tableView1 setEditing:NO animated:YES];
    } else {
        self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(editButtonSelected:)] autorelease];
        [self.tableView1 setEditing:YES animated:YES];

    }

}

Example of [UITableViewCell setEditing animated].
Add to your class a private instance variable:

@implementation MyTableViewController {
    BOOL _cellSwiped;
}
Override the setEditing method to look for the _cellSwiped variable and only propagate if we didn't swipe. The part that people seem to be missing is that _cellSwiped needs to be reset back to NO otherwise you will never be able to use the edit button after swiping!

- (void) setEditing:(BOOL)editing animated:(BOOL)animated {
    if (!_cellSwiped) {
        [super setEditing:editing animated:animated];
    } else if (!editing) {
        _cellSwiped = NO;
    }
}
Finally, add this method override to detect the swipe:

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath {
    _cellSwiped = YES;
}

UITableViewCell setEditing animated example.
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];

    if (animated) {
        [UIView beginAnimations:@"setEditingAnimation" context:nil];
        [UIView setAnimationDuration:0.3];
    }

    if (editing) {
        /* do your offset and resize here */
    } else {
        /* return to the original here*/
    }

    if (animated)
        [UIView commitAnimations];
}

End of UITableViewCell setEditing animated example article.

UITableViewCell setEditing example in Objective C (iOS).


UITableViewCell setEditing

Toggles the receiver into and out of editing mode.

- (void)setEditing:(BOOL)editing animated:(BOOL)animated

Parameters
editing
YES to enter editing mode, NO to leave it. The default value is NO .
animated
YES to animate the appearance or disappearance of the insertion/deletion control and the reordering control, NO to make the transition immediate.

Discussion of [UITableViewCell setEditing]
When you call this method with the value of editing set to YES, and the UITableViewCell object is configured to have controls, the cell shows an insertion (green plus) or deletion control (red minus) on the left side of each cell and a reordering control on the right side. This method is called on each visible cell when the setEditing:animated: method of UITableView is invoked. Calling this method with editing set to NO removes the controls from the cell.

UITableViewCell setEditing example.
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"My View Controller";
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editButtonSelected:)] autorelease];

}

- (void) editButtonSelected: (id) sender
{
    if (tableView1.editing) {
        self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editButtonSelected:)] autorelease];
        [self.tableView1 setEditing:NO animated:YES];
    } else {
        self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(editButtonSelected:)] autorelease];
        [self.tableView1 setEditing:YES animated:YES];

    }

}

Example of [UITableViewCell setEditing].
Add to your class a private instance variable:

@implementation MyTableViewController {
    BOOL _cellSwiped;
}
Override the setEditing method to look for the _cellSwiped variable and only propagate if we didn't swipe. The part that people seem to be missing is that _cellSwiped needs to be reset back to NO otherwise you will never be able to use the edit button after swiping!

- (void) setEditing:(BOOL)editing animated:(BOOL)animated {
    if (!_cellSwiped) {
        [super setEditing:editing animated:animated];
    } else if (!editing) {
        _cellSwiped = NO;
    }
}
Finally, add this method override to detect the swipe:

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath {
    _cellSwiped = YES;
}

UITableViewCell setEditing example.
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];

    if (animated) {
        [UIView beginAnimations:@"setEditingAnimation" context:nil];
        [UIView setAnimationDuration:0.3];
    }

    if (editing) {
        /* do your offset and resize here */
    } else {
        /* return to the original here*/
    }

    if (animated)
        [UIView commitAnimations];
}

End of UITableViewCell setEditing example article.

UITableViewCell prepareForReuse example in Objective C (iOS).


UITableViewCell prepareForReuse

Prepares a reusable cell for reuse by the table view'€™s delegate.

- (void)prepareForReuse

Discussion of [UITableViewCell prepareForReuse]
If a UITableViewCell object is reusable—that is, it has a reuse identifier—this method is invoked just before the object is returned from the UITableView method dequeueReusableCellWithIdentifier:. For performance reasons, you should only reset attributes of the cell that are not related to content, for example, alpha, editing, and selection state. The table view'€™s delegate in tableView:cellForRowAtIndexPath: should always reset all content when reusing a cell. If the cell object does not have an associated reuse identifier, this method is not called. If you override this method, you must be sure to invoke the superclass implementation.

UITableViewCell prepareForReuse example.
You need to prepare the cell for reuse. Try adding this to the EditableCellStyle2 implementation:

- (void)prepareForReuse {
    [super prepareForReuse];
    [self didTransitionToState:UITableViewCellStateDefaultMask];
}

Example of [UITableViewCell prepareForReuse].
And then in the UITableViewCell class when you override prepareForReuse:

- (void)prepareForReuse {
    [super prepareForReuse];
    self.myCustomImageView.imageURL = nil;
    self.myCustomImageView.image = nil;
    //do the rest of your prepareForReuse here:
    ...
}

End of UITableViewCell prepareForReuse example article.

UITableViewCell initWithStyle example in Objective C (iOS).


UITableViewCell initWithStyle

Initializes a table cell with a style and a reuse identifier and returns it to the caller.

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

Parameters of [UITableViewCell initWithStyle]
style
A constant indicating a cell style. See “Cell Styles” for descriptions of these constants.
reuseIdentifier
A string used to identify the cell object if it is to be reused for drawing multiple rows of a table view. Pass nil if the cell object is not to be reused. You should use the same reuse identifier for all cells of the same form.

Return Value of [UITableViewCell initWithStyle]
An initialized UITableViewCell object or nil if the object could not be created.

Discussion of [UITableViewCell initWithStyle]
This method is the designated initializer for the class. The reuse identifier is associated with those cells (rows) of a table view that have the same general configuration, minus cell content. In its implementation of tableView:cellForRowAtIndexPath:, the table view'€™s delegate calls the UITableView method dequeueReusableCellWithIdentifier:, passing in a reuse identifier, to obtain the cell object to use as the basis for the current row.[UITableViewCell initWithStyle]

If you want a table cell that has a configuration different that those defined by UITableViewCell for style, you must create your own custom cell. If you want to set the row height of cells on an individual basis, implement the delegate method tableView:heightForRowAtIndexPath:.

UITableViewCell initWithStyle example.
 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
          cell = [[[UITableViewCell alloc]
             initWithStyle:UITableViewCellStyleSubtitle
             reuseIdentifier:CellIdentifier]
            autorelease];
 }

   cell.textLabel.text=[Array objectAtIndex:indexPath.row];
   cell.detailTextLabel.text=@"Price";

   return cell;
 }

Example of [UITableViewCell initWithStyle].
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    return cell;
}

UITableViewCell initWithStyle example.
This worked perfect for me (Xcode 4.5.2 and iOS 6.0):

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

if( cell == nil){
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}

UILabel *title = (UILabel*) [cell viewWithTag:1000];
UILabel *summary = (UILabel*) [cell viewWithTag:1001];
[title setText:[ tableMainTitle objectAtIndex:indexPath.row]];
[summary setText:[ tableSubTitle objectAtIndex:indexPath.row]];
return cell;
}

End of UITableViewCell initWithStyle example article.

UITableViewCell didTransitionToState example in Objective C (iOS).


UITableViewCell didTransitionToState

Called on the cell just after it transitions between cell states.

- (void)didTransitionToState:(UITableViewCellStateMask)state

Parameters of [UITableViewCell didTransitionToState]
state
A bit mask indicating the state or combination of states the cell is transitioning to.

Discussion of [UITableViewCell didTransitionToState]
Subclasses of UITableViewCell can implement this method to animate additional changes to a cell when it is changing state. UITableViewCell calls this method whenever a cell transitions between states, such as from a normal state (the default) to editing mode. This method is called at the end of the animation block, which gives the custom cell a chance to clean up after the state change—for example, removing the edit and reorder controls after transitioning out of editing. Subclasses must always call super when overriding this method.[UITableViewCell didTransitionToState]

Note that when the user swipes a cell to delete it, the cell transitions to the state identified by the UITableViewCellStateShowingDeleteConfirmationMask constant but the UITableViewCellStateShowingEditControlMask is not set.

UITableViewCell didTransitionToState example.
- (void)didTransitionToState:(UITableViewCellStateMask)state {

    [super didTransitionToState:state];

    if (state == UITableViewCellStateShowingDeleteConfirmationMask || state == UITableViewCellStateDefaultMask) {
        for (UIView *subview in self.subviews) {

            if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {

                UIView *deleteButtonView = (UIView *)[subview.subviews objectAtIndex:0];
                CGRect f = deleteButtonView.frame;
                f.origin.x -= 20;
                deleteButtonView.frame = f;

                subview.hidden = NO;

                [UIView beginAnimations:@"anim" context:nil];
                subview.alpha = 1.0;
                [UIView commitAnimations];
            }
        }
    }
}

Example of [UITableViewCell didTransitionToState].
- (void)didTransitionToState:(UITableViewCellStateMask)state
{
//modified from comments here:
//http://www.erasetotheleft.com/post/overriding-the-drag-reorder-control-in-uitableviewcell/

 if(state == UITableViewCellStateEditingMask)
 {
  for (UIControl *control in self.subviews)
  {
   // Find the Reorder Control
   if ([control isMemberOfClass:NSClassFromString(@"UITableViewCellReorderControl")] && [control.subviews count] > 0)
   {
    // Create Pointer to Reorder Controls Image View
    UIImageView *imageView = [control.subviews objectAtIndex:0];

    // Set Image Views Hidden Property to NO
    imageView.hidden = YES;
   }
  }
 }
}

UITableViewCell didTransitionToState example.
You need to prepare the cell for reuse. Try adding this to the EditableCellStyle2 implementation:

- (void)prepareForReuse {
    [super prepareForReuse];
    [self didTransitionToState:UITableViewCellStateDefaultMask];
}

End of UITableViewCell didTransitionToState example article.

UITableViewCell textLabel example in Objective C (iOS).


UITableViewCell textLabel

Returns the label used for the main textual content of the table cell. (read-only)

@property(nonatomic, readonly, retain) UILabel *textLabel

Discussion of [UITableViewCell textLabel]
Holds the main label of the cell. UITableViewCell adds an appropriate label when you create the cell in a given cell style. See “Cell Styles” for descriptions of the main label in currently defined cell styles.

UITableViewCell textLabel example.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.textLabel.text = @"it was tapped";
}

Example of [UITableViewCell textLabel].
It's my subclass

#import "UITableViewCellFixed.h"
@implementation UITableViewCellFixed
- (void) layoutSubviews {
     [super layoutSubviews];
     self.textLabel.frame = CGRectMake(0, 0, 320, 20);
}
@end
It's my UITableViewControllerClass:

UITableViewCellFixed *cell = (UITableViewCellFixed *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCellFixed alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

UITableViewCell textLabel example.
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    self.textLabel.backgroundColor = [UIColor clearColor];
    self.detailTextLabel.backgroundColor = [UIColor clearColor];
}

End of UITableViewCell textLabel example article.

UITableViewCell showsReorderControl example in Objective C (iOS).


UITableViewCell showsReorderControl

A Boolean value that determines whether the cell shows the reordering control.

@property(nonatomic) BOOL showsReorderControl

Discussion of [UITableViewCell showsReorderControl]
The reordering control is gray, multiple horizontal bar control on the right side of the cell. Users can drag this control to reorder the cell within the table. The default value is NO. If the value is YES , the reordering control temporarily replaces any accessory view.

For the reordering control to appear, you must not only set this property but implement the UITableViewDataSource method tableView:moveRowAtIndexPath:toIndexPath:. In addition, if the data source implements tableView:canMoveRowAtIndexPath: to return NO, the reordering control does not appear in that designated row.

UITableViewCell showsReorderControl example.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:CellIdentifier];

 if (cell == nil) {
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
     }

cell.showsReorderControl = YES; // to show reordering control
}

Example of [UITableViewCell showsReorderControl].
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"do not leak me"];
    if (!cell) {
        cell = [[UITableViewCell alloc] init];
        cell.showsReorderControl = YES;
    }
    cell.textLabel.text = [things objectAtIndex:indexPath.row];
    return cell;
}

UITableViewCell showsReorderControl example.
- (UITableViewCell *)tableView:(UITableView *)tableview cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:kCellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:kCellIdentifier] autorelease];
}

// get the view controller's info dictionary based on the indexPath's row
NSDictionary* item = [allSounds objectAtIndex:indexPath.row];
cell.text = [item objectForKey:@\"toneName\"];
cell.showsReorderControl = YES;

return cell;
}

End of UITableViewCell showsReorderControl example article.

UITableViewCell showingDeleteConfirmation example in Objective C (iOS).


UITableViewCell showingDeleteConfirmation

Returns whether the cell is currently showing the delete-confirmation button. (read-only)

@property(nonatomic, readonly) BOOL showingDeleteConfirmation

Discussion of [UITableViewCell showingDeleteConfirmation]
When users tap the deletion control (the red circle to the left of the cell), the cell displays a "Delete" button on the right side of the cell; this string is localized.

UITableViewCell showingDeleteConfirmation example.
[cell addObserver: self forKeyPath: @"showingDeleteConfirmation"
          options: NSKeyValueObservingOptionNew context: NULL];
Then you implement the observer callback method:

- (void)observeValueForKeyPath: (NSString *) keyPath ofObject: (id) object
                        change: (NSDictionary *) change context: (void *) context
{
    if ( [keyPath isEqualToString: @"showingDeleteConfirmation"] )
    {
        UITableViewCell * cell = (UITableViewCell *) object;
        BOOL isShowing = [[change objectForKey: NSKeyValueChangeNewKey] boolValue];
        if ( isShowing == NO )
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        else
            cell.accessoryType = UITableViewCellAccessoryNone;
    }
}

Example of [UITableViewCell showingDeleteConfirmation].
//After validation fails....
UITableViewCell *aCell; 
aCell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
// validations are done and you need to ignore the delete
if ( aCell.showingDeleteConfirmation ){
    aCell.editingAccessoryView = nil;
    aCell.editingAccessoryType = UITableViewCellAccessoryNone;

}

UITableViewCell showingDeleteConfirmation example.
@implementation CustomCell
- (void)layoutSubviews {
       [super layoutSubviews];
       if (self.showingDeleteConfirmation) {
             if ([self.subviews count] < 4) return;
             UIView *delBtn = [self.subviews objectAtIndex:3];
             delBtn.frame = CGRectOffset(delBtn.frame, 0, 10);
       }
}
@end

End of UITableViewCell showingDeleteConfirmation example article.

UITableViewCell shouldIndentWhileEditing example in Objective C (iOS).


UITableViewCell shouldIndentWhileEditing

A Boolean value that controls whether the cell background is indented when the table view is in editing mode.

@property(nonatomic) BOOL shouldIndentWhileEditing

Discussion of [UITableViewCell shouldIndentWhileEditing]
The default value is YES. This property is unrelated to indentationLevel. The delegate can override this value in tableView:shouldIndentWhileEditingRowAtIndexPath:. This property has an effect only on table views created in the grouped style (UITableViewStyleGrouped); it has no effect on UITableViewStylePlain table views.

UITableViewCell shouldIndentWhileEditing example.
The shouldIndentWhileEditing property only works with grouped tables. I found that setting an indentation level of -3 does the job for plain tables. Is there a better way? Here's what I'm using now:

    if (self.tableView.style == UITableViewStylePlain) {
        cell.indentationLevel = -3;
    } else if (self.tableView.style == UITableViewStyleGrouped) {
        cell.shouldIndentWhileEditing = FALSE;
    }

Example of [UITableViewCell shouldIndentWhileEditing].
You can set a boolean on the cell to make it not indent. Just add

cell.shouldIndentWhileEditing = NO;
to wherever you create your cell.

UITableViewCell shouldIndentWhileEditing example.
Use the UITableViewDelegate method:

- (BOOL)tableView:(UITableView *)tableView
        shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{

    return NO;
}
This will work for both grouped and non-grouped UITableView types. However, if you have a grouped tableview, you can use this property on the cell:

cell.shouldIndentWhileEditing = NO;

End of UITableViewCell shouldIndentWhileEditing example article.

UITableViewCell setSelectionStyle example in Objective C (iOS).


UITableViewCell setSelectionStyle

The style of selection for a cell.

@property(nonatomic) UITableViewCellSelectionStyle selectionStyle

Discussion of [UITableViewCell setSelectionStyle]
The selection style is a backgroundView constant that determines the color of a cell when it is selected. The default value is UITableViewCellSelectionStyleBlue. See “Cell Selection Style” for a description of valid constants.

UITableViewCell setSelectionStyle example.
in didSelectRowAtIndexPath

UIActivityIndicatorView *cellActivityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[cellActivityIndicator setCenter:CGPointMake(20, 20)];
[cellActivityIndicator startAnimating];
[cell addSubview:cellActivityIndicator];
where, here [cellActivityIndicator setCenter:CGPointMake(20, 20)]; you enter position indicator in cell.

and in cellForRowAtIndexPath

[cell setSelectionStyle:UITableViewCellSelectionStyleGray];


Example of [UITableViewCell setSelectionStyle].
In cellForRowAtIndexPath use this code:

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

[cell.myLabel setHighlightedTextColor: [UIColor whiteColor]]; // for all your labels
Hope this will work for you.


UITableViewCell setSelectionStyle example.
All you have to do is set the selection style on the UITableViewCell instance using either:

cell.selectionStyle = UITableViewCellSelectionStyleNone;
or

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
Further, make sure you either don't implement -tableView:didSelectRowAtIndexPath: in your table view delegate or explicitly exclude the cells you want to have no action if you do implement it.


End of UITableViewCell setSelectionStyle example article.

UITableViewCell selectionStyle example in Objective C (iOS).


UITableViewCell selectionStyle

The style of selection for a cell.

@property(nonatomic) UITableViewCellSelectionStyle selectionStyle

Discussion of [UITableViewCell selectionStyle]
The selection style is a backgroundView constant that determines the color of a cell when it is selected. The default value is UITableViewCellSelectionStyleBlue. See “Cell Selection Style” for a description of valid constants.

UITableViewCell selectionStyle example.
in didSelectRowAtIndexPath

UIActivityIndicatorView *cellActivityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[cellActivityIndicator setCenter:CGPointMake(20, 20)];
[cellActivityIndicator startAnimating];
[cell addSubview:cellActivityIndicator];
where, here [cellActivityIndicator setCenter:CGPointMake(20, 20)]; you enter position indicator in cell.

and in cellForRowAtIndexPath

[cell setSelectionStyle:UITableViewCellSelectionStyleGray];


Example of [UITableViewCell selectionStyle].
In cellForRowAtIndexPath use this code:

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

[cell.myLabel setHighlightedTextColor: [UIColor whiteColor]]; // for all your labels
Hope this will work for you.


UITableViewCell selectionStyle example.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // A case was selected, so push into the CaseDetailViewController
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (![cell selectionStyle] == UITableViewCellSelectionStyleNone) {
        // Handle tap code here
    }
}

End of UITableViewCell selectionStyle example article.