Easy peasy:
#import "ViewController.h" @interface ViewController () @end @implementation ViewController { NSMutableArray *_data; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. _data = [NSMutableArray arrayWithObjects:@"One", @"Two", @"Three", nil]; self.tableView.editing = YES; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _data.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *identifier = @"reuseIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; } cell.textLabel.text = _data[indexPath.row]; cell.showsReorderControl = YES; return cell; } - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewCellEditingStyleNone; } - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath { [_data exchangeObjectAtIndex:sourceIndexPath.row withObjectAtIndex:destinationIndexPath.row]; } @end
EDIT:
What you asked now is a little more complicated. I created an example that puts tables in cells, which gives you nested cells. The example is very unattractive, but it works, and there is no reason why you cannot make it look beautiful, so check it out:
https://github.com/MichaelSnowden/TableViewInCell
If this does not work, try making UITableView moveSection:(NSInteger) toSection:(NSInteger) beautiful. The documentation for this method is here .
My experience with the above method was that it is very easy to use and it looks good when it called. A sensible way to use it would be to create headers using gesture recognizers. In the first touch, highlight this section and write down that indexPath, and in the second touch, call the method on two index tracks. It should work well, but you won’t get drag and drop from it.
michaelsnowden
source share