Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to wrap the word in UITableViewSectionIndex?

I want to wrap the word in section index displaying on the right side of the UItableView.

The problem is that, if the word length increases the section index width also increases and table view cell content view size reduces.And I do not want to display substring of section index array object.Since I want to display whole word in the section i have to wrap it.

-(NSArray*) sectionIndexTitlesForTableView:(UITableView *)tableView
{
    NSMutableArray *array = [[NSMutableArray alloc] init];

    for (int i = 0; i <[keys count]; i++) {
        NSString *str = [self.keys objectAtIndex:i];
           [array addObject:str];
    }

    NSArray *a =[NSArray arrayWithArray:array];
    [array release];
    return a;
}

object in the array return by sectionIndextitle method is lengthy and I want to wrap the word.

Any one knows how it can be done?

enter image description here

like image 263
Prince Kumar Sharma Avatar asked Apr 26 '12 06:04

Prince Kumar Sharma


1 Answers

you can only create your own "section index view" as a custom UIView

and it's eazy to do that

just calc the height of your tableview , calc the count of your sections

then draw your section title on it in

- (void)drawRect:(CGRect)rect

then detect the touch event

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

calc which section you touched , then call the tableview method

- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;

then put it on your tableview, eazy done!

like image 54
adali Avatar answered Sep 17 '22 11:09

adali