views:

22

answers:

2

Hi

I have refered "Managing the reordering of rows" in "UITableView Programming Guide". I have written the same code for my application for rearranging the rows of tableView but not able to rearrange the rows in tableView. The delegates "canMoveRowAtIndex" and "moveRowAtIndex" have not been called though I set tableView in editing mode through "setEditing:animated".I dont want to use core data for implementing this. Can u provide the detailed code for this?? (I would like rearrange the rows of tableView as we do for icons by long press and then moving them)

A: 

Are you sure to add properly the "Edit" button ? On my code (withoutcoredata), with a navigation controller, I have:

- (void)viewDidLoad {
  [super viewDidLoad];
  self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animate
{
  [super setEditing:editing animated:animate];
  [self.navigationItem setHidesBackButton:editing animated:YES];
}

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
  return YES;
}

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {
  //...
}
Benoît
@Benoit Yes I have added the edit button and same functions I am using but still not able to rearrange.
Vijay
A: 

If the methods aren't being called, chances are you either haven't set the table view instance's delegate outlet to point to your controller, or you've spelled the names of the delegate methods incorrectly.

One trick to help avoid misspellings is to go to the header file where the methods are declared (in this case, UITableViewController.h) copy the method declaration(s), and paste them into your source file. Otherwise, I try to use Xcode's completion mechanism to ensure that I don't accidentally misspell things.

jlehr
@jlehr I checked, all methods r rite ..
Vijay
And your delegate property is connected to the right view controller instance?
jlehr
By the way, the best way to check to see if you've spelled a method correctly is to Command-double click it in Xcode. If it's spelled right, Xcode will jump to the definition in the header file.
jlehr
@jlehr Finally I am able to rearrange the rows. Now one more problem I am facing.I am rearranging grouped table view(5 sections with 1 row each).When I rearrange one section its joining with one more section but I want intact i,e 5 sections with 1 row each even after rearrangement.How to that?
Vijay