gpt4 book ai didi

iphone - 是否可以将单词包装在 UITableViewSectionIndex 中?

转载 作者:可可西里 更新时间:2023-11-01 03:18:54 27 4
gpt4 key购买 nike

我想在 UItableView 右侧显示的部分索引中包装单词。

问题是,如果单词长度增加,部分索引宽度也会增加,表格 View 单元格内容 View 大小会减小。我不想显示部分索引数组对象的子字符串。因为我想显示整个单词我必须将其包装的部分。

-(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 方法返回的数组中的对象很长,我想换行。

有人知道怎么做吗?

enter image description here

最佳答案

您只能创建自己的“部分索引 View ”作为自定义 UIView

而且很容易做到这一点

只需计算你的tableview的高度,计算你的sections的数量

然后在上面画上你的章节标题

- (void)drawRect:(CGRect)rect

然后检测触摸事件

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

计算你触摸的部分,然后调用tableview方法

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

然后把它放在你的 tableview 上,轻松完成!

关于iphone - 是否可以将单词包装在 UITableViewSectionIndex 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10328561/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com