0

所以有时当我回到我的游戏主菜单时,我会看到一些非常特别的东西。正如您从图片中看到的那样,我在 UIView 表之外复制了单元格。现在起初我认为这是基于内存问题的图形损坏,然后我发现你可以与它们进行交互,它们是有效的单元格......不是幻影图像并且它们响应代码,所以我做了一些搜索并虽然我的表卡在编辑模式或其他什么东西,所以我在任何地方都可以调用 setediting:NO 。它仍然困扰着我。

有没有人有第一个想法可能导致这种情况?它不会一直发生,但它似乎只会发生......如果当我从另一个视图弹出回到这个屏幕时它会发生。我也无法始终如一地复制它,因此很难修复并知道是什么原因造成的。

请记住,我可能正在做或没有做我没有提到的事情,所以不要忘记询问您可能认为相关的所有内容,我很乐意通知您。

表格单元格故障 编辑:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger) tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[[CurrentGamesInfo sharedCurrentGamesInfo] _currentGames] count];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    _indexPath = indexPath;
     NSLog(@"%i",_indexPath.row);
    [_indexPath retain];

    [[CurrentGamesInfo sharedCurrentGamesInfo] SetCurrentGameWithIndex:[_indexPath row]];

    UIView *tempView = [[[tableView cellForRowAtIndexPath:indexPath] contentView] viewWithTag:200];

    if([[[(UIButton*)[tempView viewWithTag:CELL_BUTTONTEXT_ID] titleLabel] text] isEqualToString:@"Waiting"])
    {
        return;
    }

    if( ![[CurrentGamesInfo sharedCurrentGamesInfo] _selectedGame].isGameReady )
    {
        [_PopUp OptionsMessage:@"Game Not Ready" withTitle:@"Hold Your Horsies" hideBackButton:YES];
        return;
    }

    NSString *gameID = [[[CurrentGamesInfo sharedCurrentGamesInfo] _selectedGame] GetGameID];

    NSLog(@"%i",[[[CurrentGamesInfo sharedCurrentGamesInfo] _selectedGame] GetTurnNumber].intValue);

    NSData *pngData = [NSData dataWithContentsOfFile:[AppDelegate applicationDocumentDirectory:gameID]];

    UIImage *image = [UIImage imageWithData:pngData];

    PhotoImage *photoImg = [[PhotoImage alloc]init];
    [photoImg set_imageToSend:image];
    [[[CurrentGamesInfo sharedCurrentGamesInfo] _selectedGame] SetImageToSend:photoImg];
    [photoImg release];

    UIImageView * imgView = (UIImageView*)[[[[tableView cellForRowAtIndexPath:indexPath] contentView]viewWithTag:300] viewWithTag:301];
    [[[CurrentGamesInfo sharedCurrentGamesInfo]_selectedGame]setOpponentProfilePic:imgView.image];

    [self TempCurrentGameFunction];
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
} 

警告:大量功能传入

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

    GameInfo *gameThisRow = [[[CurrentGamesInfo sharedCurrentGamesInfo]_currentGames] objectAtIndex:indexPath.row];

    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"] autorelease];

    cell.selectionStyle = UITableViewCellSelectionStyleBlue;

    NSLog(@"row : %i",indexPath.row);
    NSLog(@"current game count : %i",[[[CurrentGamesInfo sharedCurrentGamesInfo] _currentGames]count]);

    NSString *gameType = @"";

    UIButton *gameStatusButton = [[UIButton alloc]initWithFrame:CGRectMake(100, -5, 90, 70)];

    Boolean isYourTurn = [[gameThisRow GetPlayerRole] intValue] ? YES : NO;

    NSString *gameStateString = @"Your Move";
    [cell setUserInteractionEnabled:YES];

    [cell setTag:ACTIVE_GAME_CELL];

    if(!isYourTurn)
    {
        //_activeGameCount--;
        gameStateString = @"Waiting";
        [cell setUserInteractionEnabled:NO];
        [cell setTag:INACTIVE_GAME_CELL];
    }

    [gameStatusButton setTitle:gameStateString forState:UIControlStateNormal];
    [[gameStatusButton titleLabel] setFont:[UIFont fontWithName:@"Fredoka One" size:10]];
    [gameStatusButton setTag:CELL_BUTTONTEXT_ID];

    if( indexPath.row  < [[[CurrentGamesInfo sharedCurrentGamesInfo] _currentGames]count])
    {
        switch ([gameThisRow gameType]) 
        {
            case 0:
                gameType = @"Open Game";
                [gameStatusButton setBackgroundImage:[UIImage imageNamed:@"buttonB_blue.png"] forState:UIControlStateNormal];
                break;

            case 1:
            {
                gameType = @"Challenge Game";
                [gameStatusButton setBackgroundImage:[UIImage imageNamed:@"buttonB_orange.png"] forState:UIControlStateNormal];

            }

                break;

            case 2:
            {
                gameType = @"Battle Game";
                [gameStatusButton setBackgroundImage:[UIImage imageNamed:@"buttonB_pink.png"] forState:UIControlStateNormal];
            }
                break;

            default:
                break;
        }
    }

    NSLog(@"%@",[[gameThisRow GetFaceBookData]objectForKey:@"name"]);

    NSString *name = [[gameThisRow GetFaceBookData]objectForKey:@"name"];

    UIView *labelView = [[UIView alloc] initWithFrame:CGRectMake(80, 10, 100, 50)];
    [labelView setTag:200];

    [labelView addSubview:gameStatusButton];
    [gameStatusButton release];

    [labelView setBackgroundColor:[UIColor clearColor]];

    UILabel *labelName = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, 100, 20)];

    NSString *text = name;

    NSArray *nameArray = [text componentsSeparatedByString:@" "];

    NSString *nameWithInitials;

    nameWithInitials = [NSString stringWithFormat:@"%@",[nameArray objectAtIndex:0]];

    for( int i = 1; i < nameArray.count; ++i )
    {
        NSString *temp = [nameArray objectAtIndex:i];
        nameWithInitials = [nameWithInitials stringByAppendingFormat:@" %C.",[temp characterAtIndex:0]];
    }

    text = nameWithInitials;

    int maxSize = 20;
    int minSize = 8;
    UIFont *font = [UIFont fontWithName:@"Fredoka One"size:maxSize];

    /* Time to calculate the needed font size.
     This for loop starts at the largest font size, and decreases by two point sizes (i=i-2)
     Until it either hits a size that will fit or hits the minimum size we want to allow (i > 10) */
    for(int i = maxSize; i > minSize; i=i-2)
    {
        // Set the new font size.
        font = [font fontWithSize:i];
        // You can log the size you're trying: NSLog(@"Trying size: %u", i);

        /* This step is important: We make a constraint box 
         using only the fixed WIDTH of the UILabel. The height will
         be checked later. */ 
        CGSize constraintSize = CGSizeMake([labelName frame].size.width, MAXFLOAT);

        // This step checks how tall the label would be with the desired font.
        CGSize labelSize = [text sizeWithFont:font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];

        /* Here is where you use the height requirement!
         Set the value in the if statement to the height of your UILabel
         If the label fits into your required height, it will break the loop
         and use that font size. */
        if(labelSize.height <= [labelName bounds].size.height)
            break;
    }
    // You can see what size the function is using by outputting: NSLog(@"Best size is: %u", i);

    // Set the UILabel's font to the newly adjusted font.
    [labelName setFont:font];

    // Put the text into the UILabel outlet variable.
    [labelName setText:text];

    [labelName setTextColor:[UIColor grayColor]];
    [labelName setBackgroundColor:[UIColor clearColor]];
    [labelName setTextAlignment:UITextAlignmentCenter];
    [labelView addSubview:labelName];
    [labelName release];

    UILabel *labelSubtitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, 100, 50)];

    [labelSubtitle setText:gameType];
    [labelSubtitle setFont:[UIFont fontWithName:@"Fredoka One" size:10]];
    [labelSubtitle setTextColor:[UIColor grayColor]];
    [labelSubtitle setBackgroundColor:[UIColor clearColor]];
    [labelSubtitle setTextAlignment:UITextAlignmentCenter];

    [labelView addSubview:labelSubtitle];
    [labelSubtitle release];

    [[cell contentView] addSubview:labelView];

    NSString *path = [NSString stringWithFormat:@"http://graph.facebook.com/%@/picture?width=200&height=200",[[gameThisRow GetFaceBookData]objectForKey:@"id"] ]; 

    UIImageView *pictureImage = [[UIImageView alloc] init];

    [pictureImage setImageWithURL:[NSURL URLWithString:path] placeholderImage:[UIImage imageNamed:@"Icon-Small.png"]success:^(UIImage *image)
     {
         pictureImage.image = [image imageScaledToSize:CGSizeMake(100, 100)];

     } failure:^(NSError *error) 
     {
         [pictureImage setImage:[[UIImage imageNamed:@"Icon-Small.png" ]imageScaledToSize:CGSizeMake(50, 50)]];
         NSLog(@"%@",[error localizedDescription]);
     }];

    NSLog(@"%@",[pictureImage image]);

    pictureImage.layer.masksToBounds = YES;

    [pictureImage setFrame:CGRectMake(pictureImage.frame.origin.x+20, 37 - 25, 50, 50)];

    UIImageView *pictureFrameView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"profile_frame.png"]];
    CGRect temp = pictureImage.frame;
    //hand & hard coded, i feel so ashamed and sullied
    temp.origin.x -= 12;
    temp.origin.y -= 9;
    temp.size.width = 70;
    temp.size.height = 73;
    [pictureFrameView setFrame:temp];

    UIView *pictureView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];

    [pictureView addSubview:pictureFrameView];
    [pictureView addSubview:pictureImage];
    [pictureImage setTag:301];
    [pictureFrameView release];
    [pictureImage release];

    [[cell contentView] addSubview:pictureView];
    [pictureView setTag:300];
    [pictureView release];



    //custom stuff start
    UIImage *rowBackground;
    //UIImage *selectionBackground;
    NSInteger sectionRows = [tableView numberOfRowsInSection:[indexPath section]];
    NSInteger row = [indexPath row];
    if (row == 0 && row == sectionRows - 1)
    {
        rowBackground = [UIImage imageNamed:@"table_bottom.png"];
        //selectionBackground = [UIImage imageNamed:@"topAndBottomRowSelected.png"];
    }
    else if (row == 0)
    {
        rowBackground = [UIImage imageNamed:@"table_top.png"];
        //selectionBackground = [UIImage imageNamed:@"topRowSelected.png"];
    }
    else if (row == sectionRows - 1)
    {
        rowBackground = [UIImage imageNamed:@"table_bottom.png"];
        //selectionBackground = [UIImage imageNamed:@"bottomRowSelected.png"];
    }
    else
    {
        rowBackground = [UIImage imageNamed:@"table_mid.png"];
        //selectionBackground = [UIImage imageNamed:@"middleRowSelected.png"];
    }
    UIImageView *imageView = [[UIImageView alloc] initWithImage:rowBackground];
    [cell setBackgroundView:imageView];
    [imageView release];
    //((UIImageView *)cell.selectedBackgroundView).image = selectionBackground;
    //custom stuff end

    __block CGRect newPos = inviteFriendsParentView.frame;
    CGRect tempCurrentGameSubMenuFrame = currentGameSubMenu.frame;
    tempCurrentGameSubMenuFrame.size.height = [friendsTable rowHeight] * [friendsTable numberOfRowsInSection:0] + 10;
    currentGameSubMenu.frame = tempCurrentGameSubMenuFrame;
    float bottomofFrameYPos =  currentGameSubMenu.frame.size.height;
    newPos.origin.y += bottomofFrameYPos;

    return cell;
}
4

0 回答 0