Class: UITableViewCell

Inherits:
UIView show all

Overview

The UITableViewCell class defines the attributes and behavior of the cells that appear in UITableView objects.

Instance Attribute Summary (collapse)

Attributes inherited from UIView

#alpha, #autoresizesSubviews, #autoresizingMask, #backgroundColor, #bounds, #center, #clearsContextBeforeDrawing, #clipsToBounds, #contentMode, #contentScaleFactor, #exclusiveTouch, #frame, #gestureRecognizers, #hidden, #layer, #multipleTouchEnabled, #opaque, #restorationIdentifier, #subviews, #superview, #tag, #transform, #userInteractionEnabled, #window

Attributes inherited from UIResponder

#inputAccessoryView, #inputView, #undoManager

Instance Method Summary (collapse)

Methods inherited from UIView

#addConstraint:, #addConstraints:, #addGestureRecognizer:, #addSubview:, #alignmentRectForFrame:, #alignmentRectInsets, animateWithDuration:animations:, animateWithDuration:animations:completion:, animateWithDuration:delay:options:animations:completion:, areAnimationsEnabled, beginAnimations:context:, #bringSubviewToFront:, commitAnimations, #constraints, #constraintsAffectingLayoutForAxis:, #contentCompressionResistancePriorityForAxis:, #contentHuggingPriorityForAxis:, #convertPoint:fromView:, #convertPoint:toView:, #convertRect:fromView:, #convertRect:toView:, #decodeRestorableStateWithCoder:, #didAddSubview:, #didMoveToSuperview, #didMoveToWindow, #drawRect:, #drawRect:forViewPrintFormatter:, #encodeRestorableStateWithCoder:, #endEditing:, #exchangeSubviewAtIndex:withSubviewAtIndex:, #exerciseAmbiguityInLayout, #frameForAlignmentRect:, #gestureRecognizerShouldBegin:, #hasAmbiguousLayout, #hitTest:withEvent:, #initWithFrame:, #insertSubview:aboveSubview:, #insertSubview:atIndex:, #insertSubview:belowSubview:, #intrinsicContentSize, #invalidateIntrinsicContentSize, #isDescendantOfView:, layerClass, #layoutIfNeeded, #layoutSubviews, #needsUpdateConstraints, #pointInside:withEvent:, #removeConstraint:, #removeConstraints:, #removeFromSuperview, #removeGestureRecognizer:, requiresConstraintBasedLayout, #sendSubviewToBack:, setAnimationBeginsFromCurrentState:, setAnimationCurve:, setAnimationDelay:, setAnimationDelegate:, setAnimationDidStopSelector:, setAnimationDuration:, setAnimationRepeatAutoreverses:, setAnimationRepeatCount:, setAnimationStartDate:, setAnimationTransition:forView:cache:, setAnimationWillStartSelector:, setAnimationsEnabled:, #setContentCompressionResistancePriority:forAxis:, #setContentHuggingPriority:forAxis:, #setNeedsDisplay, #setNeedsDisplayInRect:, #setNeedsLayout, #setNeedsUpdateConstraints, #setTranslatesAutoresizingMaskIntoConstraints:, #sizeThatFits:, #sizeToFit, #systemLayoutSizeFittingSize:, transitionFromView:toView:duration:options:completion:, transitionWithView:duration:options:animations:completion:, #translatesAutoresizingMaskIntoConstraints, #updateConstraints, #updateConstraintsIfNeeded, #viewForBaselineLayout, #viewPrintFormatter, #viewWithTag:, #willMoveToSuperview:, #willMoveToWindow:, #willRemoveSubview:

Methods inherited from UIResponder

#becomeFirstResponder, #canBecomeFirstResponder, #canPerformAction:withSender:, #canResignFirstResponder, #isFirstResponder, #motionBegan:withEvent:, #motionCancelled:withEvent:, #motionEnded:withEvent:, #nextResponder, #reloadInputViews, #remoteControlReceivedWithEvent:, #resignFirstResponder, #touchesBegan:withEvent:, #touchesCancelled:withEvent:, #touchesEnded:withEvent:, #touchesMoved:withEvent:

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Instance Attribute Details

- (UITableViewCellAccessoryType) accessoryType

The type of standard accessory view the cell should use (normal state). The accessory view appears in the right side of the cell in the table view’s normal (default) state. The standard accessory views include the disclosure chevron; for a description of valid accessoryType constants, see “Cell Accessory Type.” The default is UITableViewCellAccessoryNone. If a custom accessory view is set through the accessoryView property, the value of this property is ignored. If the cell is enabled and the accessory type is UITableViewCellAccessoryDetailDisclosureButton, the accessory view tracks touches and, when tapped, sends the data-source object a tableView:accessoryButtonTappedForRowWithIndexPath: message. The accessory-type image cross-fades between normal and editing states if it set for both states; use the editingAccessoryType property to set the accessory type for the cell during editing mode. If this property is not set for both states, the cell is animated to slide in or out, as necessary.

- (UIView) accessoryView

A view that is used, typically as a control, on the right side of the cell (normal state). If the value of this property is not nil, the UITableViewCell class uses the given view for the accessory view in the table view’s normal (default) state; it ignores the value of the accessoryType property. The provided accessory view can be a framework-provided control or label or a custom view. The accessory view appears in the right side of the cell.The accessory view cross-fades between normal and editing states if it set for both states; use the editingAccessoryView property to set the accessory view for the cell during editing mode. If this property is not set for both states, the cell is animated to slide in or out, as necessary.

Returns:

- (UIView) backgroundView

The view used as the background of the cell. The default is nil for cells in plain-style tables (UITableViewStylePlain) and non-nil for grouped-style tables UITableViewStyleGrouped). UITableViewCell adds the background view as a subview behind all other views and uses its current frame location.

Returns:

- (UIView) contentView (readonly)

Returns the content view of the cell object. (read-only) The content view of a UITableViewCell object is the default superview for content displayed by the cell. If you want to customize cells by simply adding additional views, you should add them to the content view so they will be positioned appropriately as the cell transitions into and out of editing mode.

Returns:

- (UILabel) detailTextLabel (readonly)

Returns the secondary label of the table cell if one exists. (read-only) Holds the secondary (or detail) label of the cell. UITableViewCell adds an appropriate label when you create the cell in a style that supports secondary labels. If the style doesn’t support detail labels, nil is returned. See “Cell Styles” for descriptions of the main label in currently defined cell styles.

Returns:

- (Boolean) editing

A Boolean value that indicates whether the cell is in an editable state. When a cell is in an editable state, it displays the editing controls specified for it: the green insertion control, the red deletion control, or (on the right side) the reordering control. Use editingStyle and showsReorderControl to specify these controls for the cell.

Returns:

  • (Boolean)

- (UITableViewCellAccessoryType) editingAccessoryType

The type of standard accessory view the cell should use in the table view’s editing state. The accessory view appears in the right side of the cell when the table view is in editing mode. The standard accessory views include the disclosure chevron; for a description of valid constants, see “Cell Accessory Type.” The default is UITableViewCellAccessoryNone. If a custom accessory view for editing mode is set through the editingAccessoryView property, the value of this property is ignored. If the cell is enabled and the accessory type is UITableViewCellAccessoryDetailDisclosureButton, the accessory view tracks touches and, when tapped, sends the delegate object a tableView:accessoryButtonTappedForRowWithIndexPath: message. The accessory type cross-fades between normal and editing states if it set for both states; use the accessoryType property to set the accessory view for the cell during the table view’s normal state. If this property is not set for both states, the cell is animated to slide or out, as necessary.

- (UIView) editingAccessoryView

A view that is used typically as a control on the right side of the cell when it is in editing mode. If the value of this property is not nil, the UITableViewCell class uses the given view for the accessory view in the table view’s editing state; it ignores the value of the editingAccessoryType property. The provided accessory view can be a framework-provided control or label or a custom view. The accessory view appears in the right side of the cell. The accessory type cross-fades between normal and editing states if it set for both states; use the accessoryType property to set the accessory view for the cell during the table view’s normal state. If this property is not set for both states, the cell is animated to slide or out, as necessary.

Returns:

- (UITableViewCellEditingStyle) editingStyle (readonly)

The editing style of the cell. (read-only) One of the constants described in “Cell Editing Style” is used as the value of this property; it specifies whether the cell is in an editable state and, if it is, whether it shows an insertion or deletion control. The default value is UITableViewCellEditingStyleNone (not editable). The delegate returns the value this property for a particular cell in its implementation of the tableView:editingStyleForRowAtIndexPath: method.

- (Boolean) highlighted

A Boolean value that indicates whether the cell is highlighted. The highlighting affects the appearance of labels, image, and background. When the highlighted state of a cell is set to YES, labels are drawn in their highlighted text color (default is white). The default value is is NO. If you set the highlighted state to YES through this property, the transition to the new state appearance is not animated. For animated highlighted-state transitions, see the setHighlighted:animated: method.Note that for highlighting to work properly, you must fetch the cell’s labels using the textLabel and detailTextLabel properties and set each label’s highlightedTextColor property; for images, get the cell’s image using the imageView property and set the UIImageView object’s highlightedImage property.

Returns:

  • (Boolean)

- (UIImageView) imageView (readonly)

Returns the image view of the table cell. (read-only) Returns the image view (UIImageView object) of the table view, which initially has no image set. If an image is set, it appears on the left side of the cell, before any label. UITableViewCell creates the image-view object when you create the cell.

Returns:

- (Integer) indentationLevel

Adjusts the indentation level of a cell whose content is indented. The default value of the property is zero (no indentation). The width for each level of indentation is determined by the indentationWidth property.

Returns:

- (Float) indentationWidth

The width for each level of indentation of a cell’€™s content. The default indentation width is 10.0 points.

Returns:

- (UIView) multipleSelectionBackgroundView

The background view to use for a selected cell when the table view allows multiple row selections. If this property is not nil, this view is used as the background view for a selected cell when the table view allows multiple row selections. You enable multiple row selections through the allowsMultipleSelection and allowsMultipleSelectionDuringEditing properties of UITableView.

Returns:

- (String) reuseIdentifier (readonly)

A string used to identify a cell that is reusable. (read-only) The reuse identifier is associated with a UITableViewCell object that the table-view’s delegate creates with the intent to reuse it as the basis (for performance reasons) for multiple rows of a table view. It is assigned to the cell object in initWithFrame:reuseIdentifier: and cannot be changed thereafter. A UITableView object maintains a queue (or list) of the currently reusable cells, each with its own reuse identifier, and makes them available to the delegate in the dequeueReusableCellWithIdentifier: method.

Returns:

- (Boolean) selected

A Boolean value that indicates whether the cell is selected. The selection affects the appearance of labels, image, and background. When the selected state of a cell is set to YES, it draws the background for selected cells with its title in white. The default value is is NO. If you set the selection state to YES through this property, the transition to the new state appearance is not animated. For animated selected-state transitions, see the setSelected:animated: method.

Returns:

  • (Boolean)

- (UIView) selectedBackgroundView

The view used as the background of the cell when it is selected. The default is nil for cells in plain-style tables (UITableViewStylePlain) and non-nil for section-group tables UITableViewStyleGrouped). UITableViewCell adds the value of this property as a subview only when the cell is selected. It adds the selected background view as a subview directly above the background view (backgroundView) if it is not nil, or behind all other views. Calling setSelected:animated: causes the selected background view to animate in and out with an alpha fade.

Returns:

- (UITableViewCellSelectionStyle) selectionStyle

The style of selection for a cell. 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.

- (Boolean) shouldIndentWhileEditing

A Boolean value that controls whether the cell background is indented when the table view is in editing mode. 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.

Returns:

  • (Boolean)

- (Boolean) showingDeleteConfirmation (readonly)

Returns whether the cell is currently showing the delete-confirmation button. (read-only) 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.

Returns:

  • (Boolean)

- (Boolean) showsReorderControl

A Boolean value that determines whether the cell shows the reordering control. 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.

Returns:

  • (Boolean)

- (UILabel) textLabel (readonly)

Returns the label used for the main textual content of the table cell. (read-only) 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.

Returns:

Instance Method Details

- (Object) didTransitionToState(state)

Called on the cell just after it transitions between cell states. 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.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.

Parameters:

  • state (UITableViewCellStateMask)

    A bit mask indicating the state or combination of states the cell is transitioning to.

Returns:

- (Object) initWithStyle(style, reuseIdentifier:reuseIdentifier)

Initializes a table cell with a style and a reuse identifier and returns it to the caller. 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. 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:.

Parameters:

  • style (UITableViewCellStyle)

    A constant indicating a cell style. See “Cell Styles” for descriptions of these constants.

  • reuseIdentifier (String)

    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.

Returns:

- (Object) prepareForReuse

Prepares a reusable cell for reuse by the table view’€™s delegate. 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.

Returns:

- (Object) setEditing(editing, animated:animated)

Toggles the receiver into and out of editing mode. 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.

Parameters:

  • editing (Boolean)

    YES to enter editing mode, NO to leave it. The default value is NO .

  • animated (Boolean)

    YES to animate the appearance or disappearance of the insertion/deletion control and the reordering control, NO to make the transition immediate.

Returns:

- (Object) setHighlighted(highlighted, animated:animated)

Sets the highlighted state of the cell, optionally animating the transition between states. 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. A custom table cell may override this method to make any transitory appearance changes.

Parameters:

  • highlighted (Boolean)

    YES to set the cell as highlighted, NO to set it as unhighlighted. The default is NO.

  • animated (Boolean)

    YES to animate the transition between highlighted states, NO to make the transition immediate.

Returns:

- (Object) setSelected(selected, animated:animated)

Sets the selected state of the cell, optionally animating the transition between states. The selection affects the appearance of labels, image, and background. When the selected state of a cell is YES, it draws the background for selected cells (“Reusing Cells”) with its title in white.

Parameters:

  • selected (Boolean)

    YES to set the cell as selected, NO to set it as unselected. The default is NO.

  • animated (Boolean)

    YES to animate the transition between selected states, NO to make the transition immediate.

Returns:

- (Object) willTransitionToState(state)

Called on the cell just before it transitions between cell states. 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.

Parameters:

  • state (UITableViewCellStateMask)

    A bit mask indicating the state or combination of states the cell is transitioning to.

Returns: