在扩展TableViewCell时,TableViewCell中标签和图像的位置正在发生变化

时间:2013-01-17 12:36:54

标签: iphone ios uitableview

我是这个xcode的新手。我想在双击UITableViewCell时显示更多详细信息。所以我正在扩展UITableViewCell。在展开UITableViewCell时,在展开单元格之前可见的标签和图像正在改变它们的位置,即它们正在移动到UITableViewCell的扩展部分。请建议我。

提前致谢...

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (selectedRow && indexPath.row == tappedRow && tapCount == 2)
    {
        return 200;
    }
       return 62;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(tapCount == 1 && tappedRow == indexPath.row){

        tapCount = tapCount + 1;
        annotate.hidden =YES;
        selectedRow = [tableView indexPathForSelectedRow];
        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationNone];

        annotate.hidden = NO;
        [UIView commitAnimations];

    }
    else if (tapCount == 0){

        tapCount = tapCount +1;
        tappedRow = indexPath.row;
    }

    else if (tapCount ==2 && tappedRow == indexPath.row){

        tapCount = 0;
        annotate.hidden = YES;
        [tableView setRowHeight:62];
        [tableView reloadData];
        [annotate release];
    }

    else if (tappedRow != indexPath.row){

        tapCount = 1;
        tappedRow = indexPath.row;
        annotate.hidden = YES;
        [annotate release];
    }

}

- (UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"ChooseAPlayer"];
    UILabel *lblName = (UILabel *)[cell viewWithTag:101];
    [lblName setText:[inputPlayersList objectAtIndex:[indexPath row]]];

    UILabel *Teams = (UILabel *)[cell viewWithTag:103];
    [Teams setText:[inputPlayersTeams objectAtIndex:[indexPath row]]];

    UILabel *AwayTeams = (UILabel *)[cell viewWithTag:104];
    [AwayTeams setText:[inputPlayersAwayteams objectAtIndex:[indexPath row]]];

    UILabel *PlayersPrice = (UILabel *)[cell viewWithTag:105];
    [PlayersPrice setText:[inputPlayersPrice objectAtIndex:[indexPath row]]];


    annotate.hidden = YES;

    if ( indexPath.row == tappedRow && tapCount == 2)
    {
    annotate.hidden = YES;
    annotate.tag = indexPath.row;
    annotate = [[UIView alloc] init];
    annotate.frame = CGRectMake(0, 62, 320, 138);
    annotate.backgroundColor = [UIColor greenColor];

    [cell.contentView addSubview:annotate];

    }
    UIImage *image = [UIImage   imageNamed:@"Select_white.png"];
                      UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    CGRect frame = CGRectMake(44.0, 44.0, image.size.width, image.size.height);
    button.frame = frame;
    [button setBackgroundImage:image forState:UIControlStateNormal];
    [button addTarget:self action:@selector(accessoryButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];
    button.backgroundColor = [UIColor clearColor];
    cell.accessoryView = button;

    return cell;
}

1 个答案:

答案 0 :(得分:0)

将tableview单元格中的标签自动调整为UIViewAutoresizingNone,以便在调整父视图大小后不会更改。

我希望有所帮助。