简体   繁体   中英

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:

在此处输入图片说明

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 ??

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: ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM