Can I search for "Alphabetical scroll bar"?

I currently have an idea, like a new facebook feed, where is the message from the users listed in the time order. Now on the right side I want to place the alphabetical scroll bar and when the user scrolls through any character, they can search for messages by users with a name starting with this character, is this possible?

For my understanding, this can be solved if I can capture an event when the user scrolls to each character and passes this API symbol to the server to request a database with names starting with this and send it back for display on the device.

Can someone tell me please!

+5
source share
1 answer

What you want to do is a rather unusual type of user interface, but if you really want to do this, you can do the following (you can find the tutorial here ):
In tableViewController create an array of indexes, for example. an array of alphabetic characters that you want to display on the side of your tableView , for example:

 - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { NSARRAY *characters = @[@" ", "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"];    return characters; } 

According to docs : "An array of strings that serve as section headings in the table view and are displayed in the index list on the right side of the table. The table should look in the usual style ( UITableViewStylePlain ). For example, for an alphabetical list you can return an array containing strings "A" through "Z". "

It is entirely up to you how you sort your data in tableView sections. In your case, you want all time-sorted data to be processed in one section, possibly without a special header. Therefore, your characters array starts with the @" " header at index 0, and you put all of your time-sorted entries in section 0. Then do the following method:

  - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)tappedIndex { self.savedTappedIndex = tappedIndex; return 0; } 

This method can be a bit confusing. It performs the following actions: When the user types a pointer on the side of your tableView ( @" " … @"Z" ) of a specific character in the characters array, the position of that character in the array (its index) is entered into this method. You can save it in a property. If you return to 0, as in the example, section 0 of the table will be displayed as shown. If you monitor the key value ( KVO ) of the savedTappedIndex property, you will receive a notification when the table is re-displayed. Then you can read the displayed character

 NSString *tappedCharacter = characters[self.savedTappedIndex]; 

With this symbol, you can ask a question about your server for feeds that were created by users whose name begins with this symbol.
Then the data can be displayed in the tableView , again in section 0.
Of course, you should no longer show the index on the side of the tableView .

Again, this behavior can be very confusing for the user, as it is rather unusual.

Final Note:

You should not use the hack above for a real implementation, but you can use it to test your user interface, and you will probably see that the user interface is not very good, since the index behaves differently, as usual.

+5
source

Source: https://habr.com/ru/post/1239906/


All Articles