iOS reordering a UITableView

I have a UITableView that reads data from a sql db.

When i reorder the data it only changes the top and bottom ones

Dragging 1 from top to bottom

When i let it go at 5 it only switches the top and bottom ones.

I am using the following

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {

            [myStringsArray exchangeObjectAtIndex:fromIndexPath.row withObjectAtIndex:toIndexPath.row];

}

How can i reorder the list? So it'll be 2,3,4,5,1 and not 5,2,3,4,1

Answers


Exchange is not a proper way to do it you should use this.

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
 {
     id buffer = [myStringsArray objectAtIndex:fromIndexPath.row];
     [myStringsArray removeObjectAtIndex:fromIndexPath.row];  
     [myStringsArray insertObject:buffer atIndex:toIndexPath.row];
}

Edited to match comment below.


Need Your Help

Loading package with Win32::Console - no output

perl winapi console stdout

why do I get no output, when I load this package (WinXP SP3, Strawberry Perl 5.18.1)?

How can I get unique members per category using perl?

perl hash unique

I used a hash to store members id. I avoid the duplicity using the following validation:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.