Iphone 设置显示在UITableView右侧的SectionIndex的宽度?
如何指定显示SectionIndex的帧的宽度。我在下面显示一张图片,说明我的情况Iphone 设置显示在UITableView右侧的SectionIndex的宽度?,iphone,objective-c,ios,Iphone,Objective C,Ios,如何指定显示SectionIndex的帧的宽度。我在下面显示一张图片,说明我的情况 我想将单词包装在sectionIndex中,当sectionIndex框架大小固定时,这是可能的,因此我想将sectionIndex框架的宽度设置为右侧显示的宽度。sectionIndex框架会根据其中的单词长度自动调整大小 我编写了从SectionIndexTitle返回数组的代码,如下所示: NSMutableArray *array = [[NSMutableArray alloc] init]; fo
我想将单词包装在sectionIndex中,当sectionIndex框架大小固定时,这是可能的,因此我想将sectionIndex框架的宽度设置为右侧显示的宽度。sectionIndex框架会根据其中的单词长度自动调整大小 我编写了从SectionIndexTitle返回数组的代码,如下所示:
NSMutableArray *array = [[NSMutableArray alloc] init];
for (int i = 0; i <[keys count]; i++) {
NSString *str = [self.keys objectAtIndex:i];
int length = [str length];
if (length > 9) {
str = [NSString stringWithFormat:@"%@..",[str substringToIndex:8]];
}
[array addObject:str];
}
NSArray *a =[NSArray arrayWithArray:array];
[array release];
return a;
NSMutableArray*array=[[NSMutableArray alloc]init];
对于(int i=0;i 9){
str=[NSString stringWithFormat:@“%@..”,[str substringToIndex:8]];
}
[数组addObject:str];
}
NSArray*a=[NSArray arrayWithArray:array];
[阵列释放];
返回a;
你能帮我解决这个问题吗 不幸的是,使用公共API无法自定义节索引
如果此功能对您的应用程序如此重要,您可能最终会创建一个自定义节索引视图。不幸的是,使用公共API无法自定义节索引 如果此功能对您的应用程序如此重要,您可能最终会创建一个自定义节索引视图。请参阅以下答案: 我认为定制节索引或创建自定义节索引非常困难或几乎不可能 如果你需要更多的帮助,请告诉我 希望这有帮助。请参考以下答案: 我认为定制节索引或创建自定义节索引非常困难或几乎不可能 如果你需要更多的帮助,请告诉我
希望这有帮助。我最近遇到了类似的问题,我没有时间集成自定义的sectionindex。因此,我只是用空格修改了节索引列表中的第一项:
-(NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return @[@" A ", @"B", @"C", @"D", @"E", @"F"];
}
-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
if ([title containsString:@"A"])
{
title = @"A";
}
//Your code here
}
-(NSArray*)sectionIndexTitlesForTableView:(UITableView*)表视图
{
返回[“A”、“B”、“C”、“D”、“E”、“F”];
}
-(NSInteger)tableView:(UITableView*)分区索引的tableView部分exttitle:(NSString*)标题索引:(NSInteger)索引
{
if([标题包含字符串:@“A”])
{
标题=@“A”;
}
//你的代码在这里
}
有了这个解决方案,我设法修改了节索引的宽度
希望有帮助:)我最近遇到了一个类似的问题,我没有时间集成自定义的sectionindex。因此,我只是用空格修改了节索引列表中的第一项:
-(NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return @[@" A ", @"B", @"C", @"D", @"E", @"F"];
}
-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
if ([title containsString:@"A"])
{
title = @"A";
}
//Your code here
}
-(NSArray*)sectionIndexTitlesForTableView:(UITableView*)表视图
{
返回[“A”、“B”、“C”、“D”、“E”、“F”];
}
-(NSInteger)tableView:(UITableView*)分区索引的tableView部分exttitle:(NSString*)标题索引:(NSInteger)索引
{
if([标题包含字符串:@“A”])
{
标题=@“A”;
}
//你的代码在这里
}
有了这个解决方案,我设法修改了节索引的宽度
希望有帮助:)这似乎在iPad和iPhone 5上运行良好。在cellForRow中使用它
let rightOffset: CGFloat = cell.frame.width - cell.contentView.frame.width
这似乎在iPad和iPhone5上运行良好。在cellForRow中使用它
let rightOffset: CGFloat = cell.frame.width - cell.contentView.frame.width
谢谢你的建议@Princekumar:您能找到解决方案吗?{if([[[view class]description]IsequalString:@“UITableViewIndex]”){[view setBackgroundColor:[UIColor whiteColor]];[view setFrame:CGRectMake(232,0,100,tableView.bounds.size.height)]}我已经在CellForRowatineXpath方法中应用了这个方法,它完美地设置了背景,但设置帧不起作用。为什么?谢谢你的建议@Princekumar:您能找到解决方案吗?{if([[[view class]description]IsequalString:@“UITableViewIndex]”){[view setBackgroundColor:[UIColor whiteColor]];[view setFrame:CGRectMake(232,0,100,tableView.bounds.size.height)]}我已经在CellForRowatineXpath方法中应用了这个方法,它完美地设置了背景,但设置帧不起作用。为什么会这样?