I made a simple table view with contents and code as below, but I can't view reorder control, can you tell me where my code is not correct?
row1: show UITableViewCellAccessoryDisclosureIndicator
row2: show UITableViewCellAccessoryDetailDisclosureButton
row3: show UITableViewCellAccessoryCheckmark
row4: show UITableViewCellEditingStyleNone(reorder control) in edit mode
row5: show UITableViewCellEditingStyleInsert in edit mode
row6: show UITableViewCellEditingStyleDelete in edit mode
row1: show UITableViewCellAccessoryDisclosureIndicator
row2: show UITableViewCellAccessoryDetailDisclosureButton
row3: show UITableViewCellAccessoryCheckmark
row4: show UITableViewCellEditingStyleNone(reorder control) in edit mode
row5: show UITableViewCellEditingStyleInsert in edit mode
row6: show UITableViewCellEditingStyleDelete in edit mode
Code:
#import "FirstViewController.h"
@implementation FirstViewController
- (IBAction) toggleEdit:(id)sender {
[self.tableView setEditing:!self.tableView.editing animated:YES];
if (self.tableView.editing) {
[self.navigationItem.rightBarButtonItem setTitle:@"Done"];
}
else {
[self.navigationItem.rightBarButtonItem setTitle:@"Edit"];
}
}
- (void)viewDidLoad {
self.title = @"First Level";
UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered target:self action:@selector(toggleEdit:)];
self.navigationItem.rightBarButtonItem = editButton;
[super viewDidLoad];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 12;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *First = @"First";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:First];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:First] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [[NSString alloc] initWithFormat:@"Row is %d", row + 1];
if (row % 6 == 0) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
else if (row % 6 == 1) {
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}
else if (row % 6 == 2) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else if (row % 6 == 3) {
cell.showsReorderControl = YES;
}
return cell;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
if (row % 6 == 4) {
return UITableViewCellEditingStyleInsert;
}
else if (row % 6 == 5) {
return UITableViewCellEditingStyleDelete;
}
else {
return UITableViewCellEditingStyleNone;
}
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
if (row % 6 == 3) {
return YES;
}
else {
return FALSE;
}
}
@end