Feroz
Feroz

Reputation: 699

How to sort tabular view - IOS

I want to sort a tabular view in IOS apps (Ascending, Descending). For that do we need to write our own sorting logics or any predefined methods are available in IOS?

thanks in advance.

Upvotes: 0

Views: 79

Answers (2)

user207616
user207616

Reputation:

if you have a NSArray as your data source you can sort it by calling:

myArray = [myArray sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
    return [obj1 compare:obj2];
}];

Upvotes: 1

Mihir Mehta
Mihir Mehta

Reputation: 13843

You need to write your own... at best you can sort the NSArray first and then use it in tableView's delegate methods like cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
}

so it will be sorted automatically ...

Upvotes: 0

Related Questions