Tag Archives: uitableview

Prevent First TableViewCell to be Sorted Over or Moved in UITableView

I was creating a small todo app for fun, had a UITableView Set Up populated by an SQLite database, wanted to keep the first cell the “Inbox” and have it not be moved, or have any other cell be able to be sorted above it. After hours of trying to figure out the method to do this I figured out that a few things needed to be done in a few methods:

First, tell the <b>canMoveRowAtIndexPath</b> method that the first row can not be moved when the table is in edit mode:

Second, tell the <b>canEditRowAtIndexPath</b> that the row can not be deleted:

Finally, tell the <b>targetIndexPathForMoveFromRowAtIndexPath</b> method to not let anything be dragged above the first cell, but let the rest of the cells swap any where else they want:

Hope this helps anyone that was having the same problem.

Deselect UITableViewCell on Load

If you’ve ever paid attention to mail.app in iOS, when you navigate back to the main table view of mail items, the items that you previously selected shows for a second then deselects itself and animates out. Here’s how to do that:

UITableView Delegate Methods

UITableViews work better as subclasses of UIViews instead of a stand along UITableView classes. One prime example is with iAds, in order to configure them correctly and have them display at the bottom of your table and not over the last cell, the UITableView needs to be a subview of a UIView class. No need to create a new UITableView subclass just to get the delegate methods. Copy and paste the UITableView delegate methods from below and paste into your classes implementation file: