处理使用类似Pinterest的UI的项目。所以我到目前为止创建的是一个填充了自定义单元格的UITableView。每个单元格包含3个高度自定义的UIButtons来复制列。
我的最终结果是这样的:
我提出的问题是,每当我向上滚动时,前一个单元格都会被剪切,即使我已经禁用了可能生成的所有内容。剪辑看起来像这样
[[中间的栏目]]:
代码:
-(UIView*)PinterestColumnView:(NSIndexPath*)indexPath withTag:(NSInteger)tag;
{
UIView* frameWrapper = [[[UIView alloc] initWithFrame:CGRectMake(3, 3, 94, 140)] autorelease];
[frameWrapper setUserInteractionEnabled:NO];
[frameWrapper setBackgroundColor:[UIColor whiteColor]];
UIImageView* backgroundView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 84, 130)];
[backgroundView setContentMode:UIViewContentModeScaleToFill];
backgroundView.image = [UIImage imageNamed:@"pinterestbackdrop.jpg"];
[frameWrapper addSubview:backgroundView];
[backgroundView release];
UIImageView* ColumnImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 84, 130)];
[ColumnImageView setBackgroundColor:[UIColor clearColor]];
[ColumnImageView setContentMode:UIViewContentModeScaleAspectFill];
int ColumnAddress = (((indexPath.row*3)+tag) % self.data.count);
[ColumnImageView setImage:[self retrieveImageFromURL:[[self.data objectAtIndex:ColumnAddress] objectForKey:@"gen_img_uri"]]];
[frameWrapper addSubview:ColumnImageView];
[ColumnImageView release];
return frameWrapper;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCellStyle style = UITableViewCellStyleDefault;
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:sCellIdent];
if (!cell)
{
cell = [[[UITableViewCell alloc] initWithStyle:style reuseIdentifier:sCellIdent] autorelease];
UIView* pinterestView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
[pinterestView setBackgroundColor:[UIColor clearColor]];
// Draw left column
UIButton* columnButtonLeft = [UIButton buttonWithType:UIButtonTypeCustom];
[columnButtonLeft setFrame:CGRectMake(5, 5, 100, 198)];
[columnButtonLeft setContentMode:UIViewContentModeScaleToFill];
[columnButtonLeft setImage:[UIImage imageNamed:@"pinterestwall.png"]];
[columnButtonLeft setBackgroundColor:[UIColor clearColor]];
[columnButtonLeft addButtonTarget:self action:@selector(testSelector:)];
[columnButtonLeft setTag:0];
int leftColumnAddress = (((indexPath.row*3)+columnButtonLeft.tag)% self.data.count);
[columnButtonLeft addSubview:[self PinterestColumnView:indexPath withTag:[columnButtonLeft tag]]];
[columnButtonLeft addSubview:[self makeStoryLabel:[[self.data objectAtIndex:leftColumnAddress] objectForKey:@"title"]]];
[columnButtonLeft addSubview:[self makeStylistLabel]];
[pinterestView addSubview:columnButtonLeft];
// Draw Middle Column
UIButton* columnButtonMiddle = [UIButton buttonWithType:UIButtonTypeCustom];
[columnButtonMiddle setFrame:CGRectMake(110, 30, 100, 198)];
[columnButtonMiddle setImage:[UIImage imageNamed:@"pinterestwall.png"]];
[columnButtonMiddle setBackgroundColor:[UIColor clearColor]];
[columnButtonMiddle addButtonTarget:self action:@selector(testSelector:)];
[columnButtonMiddle setTag:1];
int middleColumnAddress = (((indexPath.row*3)+columnButtonMiddle.tag)% self.data.count);
[columnButtonMiddle addSubview:[self PinterestColumnView:indexPath withTag:[columnButtonMiddle tag]]];
[columnButtonMiddle addSubview:[self makeStoryLabel:[[self.data objectAtIndex:middleColumnAddress] objectForKey:@"title"]]];
[columnButtonMiddle addSubview:[self makeStylistLabel]];
[pinterestView addSubview:columnButtonMiddle];
// Draw Right Column
UIButton* columnButtonRight = [UIButton buttonWithType:UIButtonTypeCustom];
[columnButtonRight setFrame:CGRectMake(215, 5, 100, 198)];
[columnButtonRight setImage:[UIImage imageNamed:@"pinterestwall.png"]];
[columnButtonRight setBackgroundColor:[UIColor clearColor]];
[columnButtonRight addButtonTarget:self action:@selector(testSelector:)];
[columnButtonRight setTag:2];
int rightColumnAddress = (((indexPath.row*3)+columnButtonRight.tag)% self.data.count);
[columnButtonRight addSubview:[self PinterestColumnView:indexPath withTag:[columnButtonRight tag]]];
[columnButtonRight addSubview:[self makeStoryLabel:[[self.data objectAtIndex:rightColumnAddress] objectForKey:@"title"]]];
[columnButtonRight addSubview:[self makeStylistLabel]];
[pinterestView addSubview:columnButtonRight];
[cell.contentView addSubview:pinterestView];
[pinterestView release];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell setBackgroundColor:[UIColor clearColor]];
}
return cell;
}
这是我尝试过的:
[cell setClearsContextBeforeDrawing:NO];
[cell setClipsToBounds:NO];
[cell setNeedsDisplay];
[cell setBackgroundColor:[UIColor clearColor]];
[cell setBackgroundView:nil];
任何人都有解决这个问题的神奇方法吗?