-2

テーブル ビューがあり、スクロールするとセル タイトル テキストが互いに重なります。

ここに画像の説明を入力

cellForIndexPath: の設定が間違っていますか?

ここに私のcellForRowAtIndexPathがあります:

    - (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    BOOL isLandscape = YES;
    if (nextOrientation == UIInterfaceOrientationPortrait || nextOrientation == UIInterfaceOrientationPortraitUpsideDown) {
        isLandscape = NO;
    }
    UIImageView* bgImage;
    UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:(isLandscape) ? @"landscape-cell":@"portrait-cell"]; 
    if (cell == nil){
     //   cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:(isLandscape) ? @"landscape-cell":@"portrait-cell"] autorelease];

        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier:(isLandscape)  ? @"landscape-cell":@"portrait-cell"] autorelease];


        if (isLandscape) {
            bgImage = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 480, 125)] autorelease];
            [bgImage setTag:BACK_IMAGE];
//          
            [cell addSubview:bgImage];

        }else {
            bgImage = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 125)] autorelease];
            [bgImage setTag:BACK_IMAGE];
            [cell addSubview:bgImage];

        }


    }else {
        bgImage = (UIImageView*)[cell viewWithTag:BACK_IMAGE];
    }
    for (UIView* v in cell.subviews) {
        if ([v isKindOfClass:[CatalogeView class]]) {
            [v removeFromSuperview];
        }
    }

    if (isLandscape) {
        if (IPADAPP) {
            [bgImage setFrame:CGRectMake(0, 0, 1024, 250)];
            [bgImage setImage:[ImgUtil image:@"polka_gor@2x.png"]];
            int num = 0;
            for(int i = indexPath.row*CATALOGE_ON_SHELF_HORIZONTAL; i < [cataloges count] && i < (indexPath.row + 1)*CATALOGE_ON_SHELF_HORIZONTAL; i++){
                CatalogeView* catalogeView = [cataloges objectAtIndex:i];
                [catalogeView setPosition:CGPointMake(40 + 120*(num%CATALOGE_ON_SHELF_HORIZONTAL) * 2 , 30)];
                [cell addSubview:catalogeView];
                num++;
            }

        }else{

            [bgImage setFrame:CGRectMake(0, 0, 480, 125)];
            [bgImage setImage:[ImgUtil image:@"polka_gor.png"]];
            int num = 0;
            for(int i = indexPath.row*CATALOGE_ON_SHELF_HORIZONTAL; i < [cataloges count] && i < (indexPath.row + 1)*CATALOGE_ON_SHELF_HORIZONTAL; i++){
                CatalogeView* catalogeView = [cataloges objectAtIndex:i];
                [catalogeView setPosition:CGPointMake(20 + 120*(num%CATALOGE_ON_SHELF_HORIZONTAL),15)];
                [cell addSubview:catalogeView];
                num++;
            }

        }

    }else {
        if (IPADAPP) {
            [bgImage setFrame:CGRectMake(0, 0, 768, 250)];
            [bgImage setImage:[ImgUtil image:@"polka@2x.png"]];
            int num = 0;
            for(int i = indexPath.row*CATALOGE_ON_SHELF_VERTICAL; i < [cataloges count] && i < (indexPath.row + 1)*CATALOGE_ON_SHELF_VERTICAL; i++){
                CatalogeView* catalogeView = [cataloges objectAtIndex:i];
                [catalogeView setPosition:CGPointMake(20 + 105*(num%CATALOGE_ON_SHELF_VERTICAL) * 2.5 ,30)];
                [cell addSubview:catalogeView];
                num++;
            }

        }else{
            [bgImage setFrame:CGRectMake(0, 0, 320, 125)];
            [bgImage setImage:[ImgUtil image:@"polka.png"]];
            int num = 0;
            for(int i = indexPath.row*CATALOGE_ON_SHELF_VERTICAL; i < [cataloges count] && i < (indexPath.row + 1)*CATALOGE_ON_SHELF_VERTICAL; i++){
                CatalogeView* catalogeView = [cataloges objectAtIndex:i];
                [catalogeView setPosition:CGPointMake(10 + 105*(num%CATALOGE_ON_SHELF_VERTICAL),15)];
                [cell addSubview:catalogeView];
                num++;
            }

        }

    }

    return cell;
} 

および Catalog View クラス:

    @implementation CatalogeView
@synthesize delegate;
@synthesize cataloge;
- (void)dealloc {
    [cataloge release];
    [image release];
    [title release];
    [button release];
    [super dealloc];
}

+(id) make{
    NSInteger koef = 1;
    if (IPADAPP) {
        koef = 2;
    }
    CatalogeView* ctrl = [[[CatalogeView alloc] initWithFrame:CGRectMake(0, 0, FULL_VIEW_WIDTH * koef, FULL_VIEW_HEIGTH * koef)] autorelease];
    [ctrl addAllSubviews];
    return ctrl;

}

-(void) addAllSubviews{
    NSInteger koef = 1;
    if (IPADAPP) {
        koef = 2;
    }

    if (!title) {
        title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, FULL_VIEW_WIDTH * koef, TITLE_HEIGTH * koef)];
        [title setNumberOfLines:2];
        [title setTextColor:[UIColor whiteColor]];
        [title setFont:[UIFont fontWithName:@"Helvetica" size:9  * koef]];
        [title setTextAlignment:UITextAlignmentCenter];
        [title setBackgroundColor:[UIColor clearColor]];
        [self addSubview:title];
    }
    if (!image) {
        image = [[UIImageView alloc] initWithFrame:CGRectMake(0, TITLE_HEIGTH * koef, FULL_VIEW_WIDTH * koef, IMAGE_HEIGTH * koef)];
        [image setBackgroundColor:[UIColor clearColor]];
        [self addSubview:image ];
    }

    if (!button) {
        button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, FULL_VIEW_WIDTH * koef, FULL_VIEW_HEIGTH * koef)];
        [button addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button ];
    }


}

-(void) addCatalogeInView:(CatalogeDbo*) newCataloge{
    self.cataloge = newCataloge;
    [title setText:cataloge.realName];
    [image setImage:[DownloadImage getImageWithName:[NSString stringWithFormat:@"%@.png", cataloge.image]]];
}

-(void) setPosition:(CGPoint) position{
    NSInteger koef = 1;
    if (IPADAPP) {
        koef = 2;
    }

    [self setFrame:CGRectMake(position.x, position.y, FULL_VIEW_WIDTH * koef, FULL_VIEW_HEIGTH * koef)];
}

-(void) click{
    if(cataloge){

        [delegate clGoInCataloge:cataloge];
    }
}

@end
4

7 に答える 7

1

フレームを正しく計算していない可能性があります。横向きまたは縦向きモードの場合

于 2013-10-05T02:41:10.483 に答える
0

それでも問題が解決しない場合は、以下に記入してください

cell=nil;  // use this to create new cell
if (cell == nil){
      cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:
}
于 2013-10-10T10:52:20.740 に答える
0

heightForRowAtIndexPath(または xib 設定) が CatalogView とは異なる高さを返し、そのような重複が発生するようです。また、iOS 5.x をサポートする必要がある場合は、UICollectionView (または PSTCollectionView) を使用しないのはなぜですか?

! Вовка в Простоквашино と Дюймовочка блудного попугая - можно новые мультфильмы снимать. :) (名前の重複によって引き起こされたロシアの漫画について話している人もいます)

于 2013-10-11T10:00:26.833 に答える