//Provide an index in the table for quick scrolling public override String[] SectionIndexTitles(UITableView tableView) { if (loading) { return(null); } List <string> index = new List <string>(); List <string> artists = Songs.GetListOfArtists(); string lastChar = ""; foreach (string artist in artists) { string initialLetter = ""; if (artist.Length > 4 && artist.Substring(0, 4) == "The ") { initialLetter = artist.Substring(4, 1).ToUpper(); } else if (artist.Length > 2 && artist.Substring(0, 2) == "A ") { initialLetter = artist.Substring(2, 1).ToUpper(); } else if (artist.Length > 1) { initialLetter = artist.Substring(0, 1).ToUpper(); } // Handle numbers first if (artist.Length > 1 && numbers.Contains <string>(initialLetter) && !index.Contains("#")) { index.Add("#"); continue; } // Ignore artists that start with non-alphabetic characters if (artist.Length > 1 && !alphabet.Contains <string>(initialLetter)) { continue; } // Add new initial letter to List if (initialLetter != lastChar) { lastChar = initialLetter; index.Add(initialLetter); } } return(index.ToArray()); }
// Get the section to scroll to when the side index is used public override nint SectionFor(UITableView tableView, string title, nint atIndex) { List <string> artists = Songs.GetListOfArtists(); int section = 0; foreach (string artist in artists) { string initialLetter = ""; if (artist.Length > 4 && artist.Substring(0, 4) == "The ") { initialLetter = artist.Substring(4, 1).ToUpper(); } else if (artist.Length > 2 && artist.Substring(0, 2) == "A ") { initialLetter = artist.Substring(2, 1).ToUpper(); } else if (artist.Length > 1) { initialLetter = artist.Substring(0, 1).ToUpper(); } // Ignore non-alphanumeric characters if (!alphabet.Contains <string>(initialLetter) && !numbers.Contains <string>(initialLetter)) { section++; continue; } // Is this the first artist with the initial letter equal to index letter (title parameter) or a number? if (initialLetter == title || numbers.Contains <string>(initialLetter)) { return(section); } else { section++; } } return(0); }