I am displaying in a group tableview
contents parsed from XML. I want to disable the click event on it (I should not be able to click it at all) The table contains two groups. I want to disable selection for the first group only but not the second group. Clicking the first row of second group navigates
to my tube player view
.
How can I make just specific groups or rows selectable?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.section!=0)
if(indexPath.row==0)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:tubeUrl]];
}
Thanks.
Starting in iOS 6, you can use
If you return
NO
, it disables both the selection highlighting and the storyboard triggered segues connected to that cell.The method is called when a touch comes down on a row. Returning
NO
to that message halts the selection process and does not cause the currently selected row to lose its selected look while the touch is down.UITableViewDelegate Protocol Reference
on Xcode 7 without coding you can simply do the following:
In the outline view, select Table View Cell. (The cell is nested under Table View Controller Scene > Table View Controller > Table View. You may have to disclose those objects to see the table view cell)
In the Attributes inspector, find the field labeled Selection and select None. atribute inspector With this option, the cell won’t get a visual highlight when a user taps it.
for swift 3.0 you can use below code to disable user interaction to UITableView cell
For swift 4.0 This will do the trick. It will disable the Cell in didSelectRowAtIndexPath method but keep the subviews clickable.
You can use the
tableView:willDisplayCell
method to do all the kinds of customization to a tableViewCell.In this above code, the user can only select the first row in the second section of the tableView. The rest all rows can't be selected. Thanks!~
You need to do something like the following to disable cell selection within the
cellForRowAtIndexPath
method:To show the cell grayed out, put the following within the
tableView:WillDisplayCell:forRowAtIndexPath
method:One method allows you to control the interactivity, the other allows you to control the UI appearance.