UITableView Setting some cells as "unselectable"

uitableview with multiple custom cells tutorial
uitableview cell design
custom uitableviewcell swift programmatically
cell for row at: indexpath swift 4
uitableview cells overlapping swift
uitableview tutorial swift
tableview in viewcontroller swift

How can I set the UITableView's cell property to be unselectable? I don't want to see that blue selection box when the user taps on the cell.

Set the table cell's selectionStyle property to UITableViewCellSelectionStyleNone. That should prevent it from highlighting, and you can also check that property in your tableView:didSelectRowAtIndexPath:.

Configuring the Cells for Your Table, The following example code shows how to configure a cell that uses the basic cell style. override func tableView(_ tableView: UITableView, cellForRowAt  In the attributes use Prototype cells and change the count to 2. You can have more than one format for cells. You’ll find in the outline two table view cells. Select the top one and use a Subtitle cell style named cell as the identifier. Change the background color to #FFEEEE in the color picker

To Prevent Row Selection

To completely prevent selection of the UITableViewCell, have your UITableViewDelegate implement tableView:willSelectRowAtIndexPath:. From that method you can return nil if you do not want the row to be selected.

- (NSIndexPath *)tableView:(UITableView *)tv willSelectRowAtIndexPath:(NSIndexPath *)path
    // Determine if row is selectable based on the NSIndexPath.

    if (rowIsSelectable) {
        return path;
    return nil;

This prevents the row from being selected and tableView:didSelectRowAtIndexPath: from being called. Note, however, that this does not prevent the row from being highlighted.

To Prevent Row Highlighting

If you would like to prevent the row from being visually highlighted on touch, you can ensure that the cell's selectionStyle is set to UITableViewCellSelectionStyleNone, or preferably you can have your UITableViewDelegate implement tableView:shouldHighlightRowAtIndexPath: as follows:

- (BOOL)tableView:(UITableView *)tv shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
    // Determine if row is selectable based on the NSIndexPath.

    return rowIsSelectable;

allowsSelection, If you set it to false , they cannot select rows. Setting this property affects cell selection only when the table view is not in editing mode. If you want to restrict  In this tutorial, we’ll be developing an iOS Application using Swift that has a single iOS UITableView with two different types of UITableViewCells.. Multiple Cells inside a TableView are commonly seen in the Facebook newsfeed application which hosts cells largely grouped into three types – Status Posts, Image Posts and Video Posts.

use this:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

Creating Custom Table View Cells, In the previous section, we set up our table view controller to display some sample data. Next, we're going to update our UITableViewCell UI by building a  On the other hand, cells that disappear will not be unloaded but will be reused. All in all, just a few cells will be initialized. But if you don’t set all properties every time, the content of other cells will be displayed! Let’s simulate this by setting the background color of the cells to red for every second cell:

For iOS 6+ only.

You can implement the method tableView:shouldHighlightRowAtIndexPath: in your delegate. Read more here : http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html

UITableViewController - iOS & Swift Tutorial, Set Countries as Header text: Select the cells and configure Basic as Style for all cells. A Basic Cell has one Label by default: Set some country  Arvindh Sukumar looks at how to create self sizing cells with UITableView and UICollectionView and Auto Layout in iOS 8 to allow for truly dynamic layouts.

Had this problem, too, tried everything already mentioned. The final trick, which got rid of the "blue flash" at selecting a table cell was adding this line:

self.myTableView.allowsSelection = NO;

Not sure whether it was this one line or everything combined, but as total grand result I get no more blue selection or even the blue flash. Happy!

How to make UITableViewCells auto resize to their content, How to make UITableViewCells auto resize to their content resize to fit their content as long as your cells use Auto Layout to configure themselves. The situation is slightly more complicated when you want some cells to be  Static UITableView's have very specific use cases. Some of these use cases can be menu's or the settings of your app. These two examples would generally have static content, but that doesn't mean that they should not be able to change based on user input. One such example could be when a user turns a setting on or off. This user interaction could allow for more options to be displayed, for eg

Table View Guide, The UITableView has two delegates that you must provide by setting the Since our table had only a few simple cells you might not have noticed any  UITableView set to static cells. Is it possible to hide some of the cells programmatically? you can hide and show cells in a static UITableView - and with

Self-Sizing Table View Cells in Practice, That said, fixed-height cells can still be appropriate in a few cases. You don't need to set an estimatedRowHeight because UITableView will determine its own​  Table views are a collaboration between many different objects, including: Cells. A cell provides the visual representation for your content. You can use the default cells provided by UIKit or define custom cells to suit the needs of your app. Table view controller. You typically use a UITable View Controller object to manage a table view. You

Self-Sizing Cells with UITableView and Auto Layout, With iOS 8, UITableView s and UICollectionView s have embraced Auto Layout. We'll configure the cells and view controllers later. some jumpiness while scrolling, as iOS expands or collapses the cell to its proper height. For example, some rows of a table view can have content based on the image and text properties of a UITableViewCell in a predefined style, while other rows can be based on a customized UITableViewCell that defines a special format for its content. When providing cells for the table view, there are three general approaches you can take.

  • Note recent googlers: The way to do this as of iOS 6 and greater is tableView:shouldHighlightRowAtIndexPath: as noted by Ayush below
  • Kendall is right. Follow Sebastian Celis' answer to prevent didSelectRowAtIndexPath from being called in the first place. You should also set selectionStyle, though, to prevent the highlighting.
  • yeah i suppose the Sebastian Celis' answer to be the correct answer, thanks Daniel
  • Storyboard fans using static TableViews can select a UITableViewCell and under Attributes Inspector can find the Selection Field and set it to None
  • Thanks! Exactly what I needed.
  • This should be the accepted answer in my opinion. It actually fixes the problem instead of masking it.
  • Note that tableView:willSelectRowAtIndexPath: is called after highlighting the cell, which will produce a flicker. From Apple's description: This method is not called until users touch a row and then lift their finger; the row isn't selected until then, although it is highlighted on touch-down.
  • I agree with @simpleBob. In order to use this solution, you need to also set cell.selectionStyle to UITableViewCellSelectionStyleNone on the unselectable rows. Otherwise it looks tacky.
  • Then the best answer is still the accepted answer. You can just choose to do nothing in didSelectRowAtIndexPath because willSelectRowAtIndexPath will always be called anyway.
  • That only stops the selection color from showing, didSelectRowAtIndexPath is still called.
  • This is also exactly the same answer as Daniel Dickison's to this question.