Jim
Jim

Reputation: 9234

iPhone: UITableView reorder rows button

I have UITableView with custom table row. What I need is to have possibility to reorder rows. so in ViewDidLoad i add:

- (void)viewDidLoad {
  [super viewDidLoad];
    [self.myTableView setEditing: YES animated: YES];
}

also add next methods:

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


- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
    editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  return UITableViewCellEditingStyleNone;
}


- (BOOL)tableView:(UITableView *)tableView
    shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
 }


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

Also I set bg color for my custom table row:

- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *customTableRow = @"customTableRow";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
    customTableRow];
if (cell == nil) {
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"customTableRow"
        owner:self options:nil];
    if (nib.count > 0) {
        cell = self.customTableRow;
    }
}
cell.contentView.backgroundColor = [UIColor colorWithRed:(228.0f/255.0f)
    green:237.0f/255.0f blue:244.0f/255.0f alpha:1.0];
return cell;
}

And then I run my app and I had an unexpected view:

enter image description here

So I have tow questions: 1.So why it so ? Reorder button is not transparent ??
2.How to change that button to my on image ??

Upvotes: 0

Views: 769

Answers (1)

Alexsander Akers
Alexsander Akers

Reputation: 16024

The problem is that you're changing the background color of the contentView. Have you tried changing the background color of the cell itself in -tableView:willDisplayCell: forRowAtIndexPath:?

Upvotes: 1

Related Questions