使UITableView可以通过索引滚动 [英] Make UITableView scrollable by index

查看:148
本文介绍了使UITableView可以通过索引滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个 UITableView 索引,以便更快地滚动一个大的 UITableView ,我有索引显示在右边,但当我尝试滚动它时,它不起作用..

I am trying to create a UITableView index for faster scrolling of a large UITableView, I have the index showing up on the right but when I try to scroll with it, it does not work..

我想知道我是否遗漏了一些东西,所以我想知道是否还有别的东西,或者其他什么东西沿着这些方向。

I am wondering if I have missed something so I am wondering if there is something else I have to do, or something along those lines.

#pragma - TableView Index Scrolling

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {

    if(searching)
        return nil;

    NSMutableArray *tempArray = [[NSMutableArray alloc] init];
    [tempArray addObject:@"A"];
    [tempArray addObject:@"B"];
    [tempArray addObject:@"C"];
    [tempArray addObject:@"D"];
    [tempArray addObject:@"E"];
    [tempArray addObject:@"F"];
    [tempArray addObject:@"G"];
    [tempArray addObject:@"H"];
    [tempArray addObject:@"I"];
    [tempArray addObject:@"J"];
    [tempArray addObject:@"K"];
    [tempArray addObject:@"L"];
    [tempArray addObject:@"M"];
    [tempArray addObject:@"N"];
    [tempArray addObject:@"O"];
    [tempArray addObject:@"P"];
    [tempArray addObject:@"Q"];
    [tempArray addObject:@"R"];
    [tempArray addObject:@"S"];
    [tempArray addObject:@"T"];
    [tempArray addObject:@"U"];
    [tempArray addObject:@"V"];
    [tempArray addObject:@"W"];
    [tempArray addObject:@"Y"];
    [tempArray addObject:@"X"];
    [tempArray addObject:@"Z"];

    return tempArray;
}

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

    if(searching)
        return -1;

    return index % 2;
}


推荐答案

表格视图需要是按字母顺序分组我相信 - 临时数组不知道如何将您选择的字母翻译成特定索引(它不知道a,b或c是什么意思)。

The table view needs to be grouped alphabetically I believe - The temp array doesn't know how to translate the letter that you select into a specific index (it doesn't know what "a", "b", or "c" mean).

如果您查看ipod歌曲列表,您会注意到每个字母组都有一个字母部分分隔符。您需要将表格对象分组为以字母标题的部分,以便将字母A转换为索引。 apple的ipod列表实际上做的不是滚动到第一个A条目,而是滚动到A部分的开头。

If you take a look at the ipod song list, you'll notice that each letter group has a letter section divider. You'll need to group your table objects into sections titled with letters in order to translate the letter "A" to an index. What apple's ipod list is actually doing is not scrolling to the first "A" entry, but the beginning of the "A" section.

这篇关于使UITableView可以通过索引滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆