簡體   English   中英

如何在音樂播放器應用程序ios /中實現字母滾動條

[英]how to implement alphabetic scrollbar like in music player app ios /

我需要像在音樂應用程序中那樣實現字母滾動條 誰能幫我做那個代碼。 當我在互聯網上搜索時,無法在任何地方獲取該代碼。

我需要右側uitableview上的滾動條

我需要像這樣的滾動條。

滾動條

@interface yourViewcontroller ()
{
 NSArray * IndexTitles;
}

  - (void)viewDidLoad
{
[super viewDidLoad];

  IndexTitles = @[@"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J", @"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z"];

 }

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return IndexTitles;
}

 // - (NSInteger)tableView:(UITableView *)tableView 
              sectionForSectionIndexTitle:(NSString *)title 
              atIndex:(NSInteger)index
// {
   //  return index;
// }

需要參考本教程

我按照以下方式使用它來顯示字母滾動條,並在單擊任何字母時也轉到該部分。 注意:我的表格視圖有n個部分,每個部分只有1行(這就是我的要求)。 因此,單擊任意字符將滾動到該部分。 這也可以照顧您單擊沒有匹配結果的字母的情況。

例如,您單擊F 在indexSectionTitles中沒有以F開頭的條目,它僅直到D(Doll)為止。 所以我會嘗試之前移動到部分FE 因此,這繼續進行,並且將使用前面具有最近字符的部分。

var indexTitles = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
var indexSectionTitles: [String] = ["Apple", "Ball", "Car", "Doll"]

func tableView(tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int {
    if indexSectionTitles.indexOf(title) != nil {
        return indexSectionTitles.indexOf(title)!
    }
    else {
        let char = title as NSString
        let prevCharIndex = getPrevName(char)
        print("prevCharIndex; ", prevCharIndex)
        return prevCharIndex
    }
}

func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? {
    return indexTitles
}

func getPrevName(title: NSString) -> Int {
    if title.isEqualToString("") {
        return 0
    }
    let charInt = title.characterAtIndex(0) - 1
    let charStr = String(UnicodeScalar(charInt))
    if indexSectionTitles.indexOf(charStr) != nil {
        return indexSectionTitles.indexOf(charStr)!
    }
    return getPrevName(charStr)
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM