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.
You trap selections with these data source methods.
In these methods, you check if the selected row is one you want to be selectable. If it is, take an action, if not, do nothing.
Unfortunately, you can't turn off selection for just one section. It's the whole table or nothing.
You can however set the table cells
selectionStyle
property toUITableViewCellSelectionStyleNone
. I believe that will make the selection invisible. Combined with the above methods that should make the cells look completely inert from the user's perspective.Edit01:
If you have a table in which only some of the rows are selectable it is important that the cells of the selectable rows be visually distinct from the non-selectable rows. The chevron accessory button is the default way to do this.
However you do it, you don't want your users trying to select rows and thinking the app has malfed because the row doesn't do anything.
I found this handy as it works with both static and dynamic tables. I only set the disclosure indicator on those cells I want to allow selection.
For Xcode 6.3:
For swift:
To stop just some cells being selected use:
As well as preventing selection, this also stops tableView:didSelectRowAtIndexPath: being called for the cells that have it set.
My solution based on data model: