Jordan H
Jordan H

Reputation: 55725

How to disable user interaction of section index for UITableView?

I have implemented a section index, letters at the right of the table view that allow quickly jumping to a section, in my app. I would like to disable user interaction with that section index in some situations, but there is no property on UITableView that allows directly accessing the section index.

How can I disable user interaction for section indexes?

I have disabled interaction with the table itself so that you cannot scroll or tap any cell, but this still allows interacting with the section indexes, so it will scroll to each section upon tapping a section icon.

self.tableView.userInteractionEnabled = NO;

If it's not possible to disable interaction with the section index itself, is there a way to prevent changing the scroll position of the table? That's exactly what I wanted to obtain.

Upvotes: 1

Views: 1739

Answers (3)

BonanzaDriver
BonanzaDriver

Reputation: 6452

As an alternative, if you wish to allow scrolling - so users can see what's there - but prevent them from making selections, etc. you can do the following instead:

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.tableViewIsDidabled)
        return nil;
    else
        return indexPath;
}

and, setting the sectionForSectionIndexTitle to nil.

Upvotes: 2

Jordan H
Jordan H

Reputation: 55725

I found a solution.

Keep a BOOL to know when the section indexes should be disabled.

Then in tableView:sectionForSectionIndexTitle:atIndex: just return -1 to prevent scrolling when tapping indexes.

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
    if (self.tableViewIsDisabled) {
        return -1;
    }
    ...
}

Upvotes: 1

Marcio Romero Patrnogic
Marcio Romero Patrnogic

Reputation: 1156

UITableView *tab;

mm to disable scroll..

tab.scrollEnabled = NO;

if you wanna use it in certain situations.. you can try with a powerful..

if(...)
tab.scrollEnabled = NO;

Upvotes: 0

Related Questions