0

我使用BVReorderTableView https://github.com/bvogelzang/BVReorderTableView重新排序表视图中的行。但是我有一个问题:当我将 UIButton 添加到每一行时,这个按钮总是显示清晰的颜色。一旦选择了行,这个按钮就会显示出来。

我试过这段代码:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell;

    cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    UIButton *prioritybtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        [prioritybtn setFrame:CGRectMake(220, 0, 70, 32)];
        [prioritybtn setTag:4000];
        [cell.contentView addSubview:prioritybtn];

    }
     UIButton *priorityButton = (UIButton*)[cell.contentView viewWithTag:4000];
    if ([[items objectAtIndex:indexPath.row] isKindOfClass:[NSString class]] &&
        [[items objectAtIndex:indexPath.row] isEqualToString:@"DUMMY"]) {
        cell.textLabel.text = @"";
        cell.contentView.backgroundColor = [UIColor clearColor];
        prioritybtn.hidden= YES;
    }
    else {

       cell.textLabel.text = [items objectAtIndex:indexPath.row];
        [priorityButton setSelected:NO];
        [priorityButton setTitle:@"Priority" forState:UIControlStateNormal];
        priorityButton.enabled = YES;
    }

    return cell;
}

另外,我只想在第一行隐藏按钮,其他行仍然显示。我怎样才能做到这一点?谢谢

4

3 回答 3

3

要隐藏第一行的按钮:

    if (indexPath.row == 1){
      prioritybtn.hidden = YES;
      prioritybtn.userInteractionEnabled = NO;
    } else {
      prioritybtn.hidden = NO;
      prioritybtn.userInteractionEnabled = YES;
}

在此之前添加return cell;

关于颜色,在初始化按钮的地方添加:

 UIButton *prioritybtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    prioritybtn.backgroundColor = [UIColor greenColor]; //put the color you want
于 2013-11-11T08:35:06.677 回答
0

试试这样: -

 cell.selectionStyle = 
  UITableViewCellSelectionStyleNone;
于 2013-11-11T09:04:24.563 回答
0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{


    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell;
    UIButton *reletedbtn=nil;
    UILabel *Nameoflb=nil;

    cell = [tableeample dequeueReusableCellWithIdentifier:CellIdentifier];
      if (cell == nil)
      {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }
    Nameoflb = [[UILabel alloc] initWithFrame:CGRectMake(0,0,200,40)];
    Nameoflb.backgroundColor=[UIColor clearColor];
    Nameoflb.textAlignment=NSTextAlignmentCenter;
    Nameoflb.textColor=[UIColor blackColor];
    [Nameoflb setFont:[UIFont fontWithName:@"Helvetica-Bold" size :14]];
    Nameoflb.text=[dataarray objectAtIndex:indexPath.row];
    [[cell contentView] addSubview:Nameoflb];
    if (indexPath.row!=0)
    {
        reletedbtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
        reletedbtn.frame=CGRectMake(Nameoflb.frame.origin.x+Nameoflb.frame.size.width, Nameoflb.frame.origin.y+10,40, 25);
        reletedbtn.tintColor=[UIColor redColor];
        [reletedbtn setTitle:@"butoon" forState:UIControlStateNormal];

        //[reletedbtn addTarget:self action:@selector(statusMasseage:) forControlEvents:UIControlEventTouchUpInside];
        //reletedbtn.tag=1;
        [[cell contentView] addSubview:reletedbtn];

    }


    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;

}
于 2013-11-11T09:45:25.240 回答