是否可以在UITableViewSectionIndex中包装单词? [英] Is it possible to wrap the word in UITableViewSectionIndex?
问题描述
我想在UItableView右侧的部分索引中显示单词。
I want to wrap the word in section index displaying on the right side of the UItableView.
问题是,如果字长增加了部分索引宽度也增加和表视图单元格内容视图大小reduce.And我不想显示节索引数组对象的子字符串。因为我想在我必须包装它的部分显示整个单词。
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;
}
数组中的对象返回sectionIndextitle方法是冗长的,我想包装单词。
object in the array return by sectionIndextitle method is lengthy and I want to wrap the word.
任何人都知道怎么做?
推荐答案
你只能创建你自己的部分索引视图作为一个自定义的UIView
you can only create your own "section index view" as a custom UIView
并且它很乐意这样做
你的tableview的高度,计算你的部分的数量
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
然后检测到触摸事件
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
计算您触摸的部分,然后调用tableview方法
calc which section you touched , then call the tableview method
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;
然后将它放在你的tableview上,完成了!
then put it on your tableview, eazy done!
这篇关于是否可以在UITableViewSectionIndex中包装单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!