ios - 自定义单元格在 UITableView 中重叠

标签 ios xcode uitableview ios7

我有一个名为 GameCell 的自定义单元类,UI 在 Storyboard 中创建。当我的单元格加载时,它们会叠加加载。 cell.clipsToBounds YES 和 NO 会出现此问题,只是变化不同:

cell.clipsToBound = YES

cell.clipsToBound = NO

我也试过 [cell setClipsToBounds:(BOOL)] 但没有成功。

这是我的 cellForRowAtIndexPath 方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"gameCell";

GameCell *cell = (GameCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];


[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[cell.contentView.superview setClipsToBounds:NO];
NSLog(@"made a cell");
PFObject *myPartners = [self.games objectAtIndex:indexPath.row];
PFUser *partner = [self.partnerList objectAtIndex:indexPath.row];

// Cell profile image
cell.profileImage.layer.cornerRadius = cell.profileImage.frame.size.width / 2;
cell.profileImage.clipsToBounds = YES;

if([partner objectForKey:@"profilePic"]!=nil){
cell.profileImage.image = [partner objectForKey:@"profilePic"];
}
else {
    cell.profileImage.image = [UIImage imageNamed:@"smile_green.png"];
} 

//Cell indicators
if((int)[myPartners objectForKey:@"sent"]==1){
    cell.myIndicator.image = [UIImage imageNamed:@"arrow_icon_dbl.png"];
}
else if ([myPartners objectForKey:@"sent"]==0){
    cell.myIndicator.image = [UIImage imageNamed:@"arrow_icon.png"];
}

cell.partnerName.text = [myPartners objectForKey:@"receiverName"];
cell.gameId = myPartners.objectId;

// Cell drop shadow
[cell.cellView.layer setShadowColor:[UIColor blackColor].CGColor];
[cell.cellView.layer setShadowOpacity:0.5];
[cell.cellView.layer setShadowRadius:2.0];
[cell.cellView.layer setShadowOffset:CGSizeMake(1.0, 1.0)];

// Cell buttons
if([myPartners objectForKey:@"picture"]!=nil) {
            [cell.myPlay setEnabled:NO];
} else {
           [cell.myPlay setEnabled:YES];
}

return cell;
}

View 是嵌入在 NavigationController 中的 UITableViewController

最佳答案

你已经使用了dequeueReusableCellWithIdentifier:

像这样使用

NSString *CellIdentifier = [NSString stringWithFormat:@"Cell %d",indexPath.row];

UITableViewCell *cell=[self.tableView cellForRowAtIndexPath:indexPath];

if (cell == nil)
{
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

并查看此链接。

UITableView cell Contents are disappearing and overlapping when scrolled in UITableViewcell?

关于ios - 自定义单元格在 UITableView 中重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25496931/

相关文章:

XCode 项目在其他 Mac 上缺少文件

swift - 多个 UITableViewCells 每个都有 UIProgressView 更新非常慢

iphone - 自定义 Tableview 单元格出现问题

iphone - 是否有捕获控制台日志的 iPad/电话应用程序(来自 iPhone 配置实用程序)

ios - RestKit 0.20 映射问题(使用来自 API 的 JSON)

objective-c - Xcode 7.3 归档结束,但 Xcode 崩溃,错误为 : bundleIdentifier should be a non-empty string,,但它是一个空字符串

ios - 我可以在 iOS 上指定 AutoLayout 约束以间隔到最近的可见邻居吗?

ios - 将 int 转换为 NSTimeInterval

ios - 从后台返回后的 AVCapturesession 处理

ios - 如何通知 UITableViewController 来自 UITableViewCell 子类的事件?