【问题标题】:iPhone: UITableView reorder rows buttoniPhone:UITableView 重新排序行按钮
【发布时间】:2012-03-20 23:56:12
【问题描述】:

我有带有自定义表格行的 UITableView。我需要的是有可能重新排序行。所以在 ViewDidLoad 我添加:

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

还添加下一个方法:

- (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;
 }

我还为我的自定义表格行设置了背景颜色:

- (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;
}

然后我运行我的应用程序,我看到了一个意想不到的视图:

所以我有两个问题: 1.那为什么会这样?重新排序按钮不透明??
2.如何将该按钮更改为我的图像??

【问题讨论】:

    标签: iphone uitableview


    【解决方案1】:

    问题是您正在更改contentView 的背景颜色。您是否尝试过更改-tableView:willDisplayCell: forRowAtIndexPath: 中单元格本身的背景颜色?

    【讨论】:

    • 我没有,但我会的。问题 2 呢?
    • 您可以尝试遍历单元格的子视图并用您自己的按钮替换按钮?
    • Alexsander,很抱歉,更改单元格的背景颜色(而不是其内容视图)对单元格没有任何可见的影响。此外,重新排序控件不包含在单元格的子视图中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-30
    • 1970-01-01
    相关资源
    最近更新 更多