テーブル ビューがあり、スクロールするとセル タイトル テキストが互いに重なります。
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