Sarah
Sarah

Reputation: 1595

Display the UItableView index to the left of table instead of right

I'm using Indexed UITableView by implementing the following delegate methods:

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView 

The index is displayed on the right of the table. I was wondering if the index can be displayed on the left instead.

Thanks,

Upvotes: 1

Views: 4024

Answers (4)

Basheer_CAD
Basheer_CAD

Reputation: 4919

You can move the tableView index view to the left, but just a little bit so you don't get your app rejected )). Here is how:

// somewhere in your code for example in table view delegate method add this code
// take the index view, which is the last subview on the tableView
UIView *indexView = [[self.tableView subviews]lastObject];

// now take its frame and play with it
CGRect indexViewRect = indexView.frame;
indexViewRect.origin.x -= 50;      // move it to the left by -50
indexView.frame = indexViewRect;   // set the new frame 

Thats it :)

By the way, I dont think Apple will reject your app if you move the index view to the most left, because I saw this on their contacts app on the iPad, but anyway at your risk.

Update: Fully customizable and easy to use ScrollBar you can find here: https://github.com/BasheerSience/BRScrollBar

Upvotes: 3

Vincent Guerci
Vincent Guerci

Reputation: 14419

Even not officially exposed by iOS APIs, it should be possible to move the index, by "hacking" a bit.

First you have to locate the the index in the UITableView subviews tree. One simple way to do this is to put a breakpoint at runtime and use that:

 po [myTableView recursiveDescription]

This will print the views tree and by analyzing it you should find a way to programmatically find the UIView that interests you and just move it (view.frame.origin), and that, without using any private API

But before trying this, think twice. That index is on right side for a good reason, most people are right handed with the thumb on that right side... It would be hard to use on other side.

Upvotes: 1

Rayfleck
Rayfleck

Reputation: 12106

I don't think the api exposes that component. So sadly, you'd have to suppress rotations and hold the phone upside down, and this would be a very poor user experience. (Just a joke, don't downvote me)

Upvotes: 1

Ludovic Landry
Ludovic Landry

Reputation: 11774

No, the style and position of this index is not configurable (unfortunately).

Upvotes: 2

Related Questions