Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The simplest way, using the built-in methods, is as follows:</p> <p>First, set your table cell to have shows reorder control on. Simplest example (using ARC):</p> <p>This is assuming <code>NSMutableArray *things</code> has been created somewhere else in this class</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"do not leak me"]; if (!cell) { cell = [[UITableViewCell alloc] init]; cell.showsReorderControl = YES; } cell.textLabel.text = [things objectAtIndex:indexPath.row]; return cell; } </code></pre> <p>Implement your two <code>UITableViewDelegate</code> methods, like this:</p> <p>This method tells the tableView it is allowed to be reordered</p> <pre><code>-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } </code></pre> <p>This is where the tableView reordering actually happens</p> <pre><code>-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath { id thing = [things objectAtIndex:sourceIndexPath.row]; [things removeObjectAtIndex:sourceIndexPath.row]; [things insertObject:thing atIndex:destinationIndexPath.row]; } </code></pre> <p>and then somehow, somewhere, set editing to true. This is one example of how you can do this. The tableView must be in editing mode in order for it to be reordered.</p> <pre><code>- (IBAction)doSomething:(id)sender { self.table.editing = YES; } </code></pre> <p>Hope that serves as a concrete example.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload