1

我是这个 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;
}
4

1 回答 1

0

将表格视图单元格中标签的自动调整大小设置为,UIViewAutoresizingNone以便在调整父视图大小后它们不会改变。

我希望这会有所帮助。

于 2013-01-17T12:53:23.703 回答