简体   繁体   中英

how to sort the custom cell of an tableview containing 2 similar and 1 different controls

i have made a table view using custom cell. My custom cell contains one image view(for showing movie image) and 2 labels( 1 for showing name and 1 for time) and one button for sorting which i have taken in navigation control bar. Now i want that on click of button it should sort the cell according to movie name.

What i have done so far is i have taken an array to store the strings of the uicontrols like strng_name for movie name, strng_time for time and strng_imge for image. and to sort it on the basis of name of movie I have taken one NSDictionary and setting key as name of movie and object or value as a array of strings. But when iam setting the value of cell components iam not finding any way to fetch value from dicitonary?

Can anyone please help me? If iam going wrong then please tell me an alternative.

Try sorting the DataSource Array of your UITableView. To do so, add an Action-Method to your Button where you can perform the sorting algorithm.

Then don't forget to reload the TableView.

[tableView reloadData]; 

To retrieve values of NSDictionary use following method:

[dictionary valueForKey:@"strng_name"];

If I understand it right this should give you an NSArray with the strings of your data

You need to sort your data source using a method when you click a button

id customSort = ^(NSString * key1, NSString * key2){
    return [key1 compare:key2];
};

NSArray *sortedArray = [unsortedArray sortedArrayUsingComparator:customSort];

And then reload data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM