开发者

Problem in Managing the reordering og rows in UITableView

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 a开发者_StackOverflow社区s we do for icons by long press and then moving them)


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 {
  //...
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜