我的應用程序定製的UITableViewCell大高度470px。 我完全以編程方式創建了自定義單元格。自定義的UITableViewCell不顯示在滾動時滿格之前顯示的數據
這是我的cellForRowAtIndexPath方法
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
pixDealsTableViewCell *dealCell = (pixDealsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"Deals" forIndexPath:indexPath];
if (dealCell == nil) {
dealCell = [[pixDealsTableViewCell alloc] init];
}
dealCell.dBusinessLogo.image = [pixUtil imageWithImage:[UIImage imageNamed:@"profile_icon"] scaledToSize:CGSizeMake(60, 60)];
[dealCell.dBusinessName setTitle:@"Business Name" forState:UIControlStateNormal];
dealCell.dTimeAgo.text = [NSString stringWithFormat:@"5 min ago"];
[dealCell.dHeading setTitle:@"Deals Head" forState:UIControlStateNormal];
[dealCell.dDescription setTitle:@"Descriptionskjdfnkjsdnfis" forState:UIControlStateNormal];
dealCell.dImage.image = [pixUtil imageWithImage:[UIImage imageNamed:@"carrier.png"] scaledToSize:CGSizeMake(290, 250)];
[dealCell.dLike setTitle:@"Like" forState:UIControlStateNormal];
[dealCell.dShare setTitle:@"Share" forState:UIControlStateNormal];
return dealCell;
}
這是我的自定義單元格的init方法
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
NSLog(@"NEW CELL");
customRed = [[UIColor alloc]initWithRed:209.0f/255.0f green:19.0f/255.0f blue:38.0f/255.0f alpha:1.0f];
[self setBackgroundColor:[UIColor grayColor]];
containerCell = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 300, 700)];
[containerCell setBackgroundColor:[UIColor whiteColor]];
self.dBusinessLogo = [[UIImageView alloc]initWithFrame:CGRectMake(15, 15, 60, 60)];
self.dBusinessName = [[UIButton alloc]initWithFrame:CGRectMake(80, 20, 225, 20)];
[self.dBusinessName setTitle:@"Business Name" forState:UIControlStateNormal];
self.dBusinessName.titleLabel.font = [UIFont boldSystemFontOfSize:14];
[self.dBusinessName addTarget:self action:@selector(haveAccount:) forControlEvents:UIControlEventTouchUpInside];
[self.dBusinessName setTitleColor:customRed forState:UIControlStateNormal];
self.dTimeAgo = [[UILabel alloc]initWithFrame:CGRectMake(80, 50, 225, 15)];
self.dHeading = [[UIButton alloc]initWithFrame:CGRectMake(15, 80, 290, 20)];
self.dHeading.titleLabel.font = [UIFont boldSystemFontOfSize:14];
[self.dHeading addTarget:self action:@selector(haveAccount:) forControlEvents:UIControlEventTouchUpInside];
[self.dHeading setTitleColor:customRed forState:UIControlStateNormal];
self.dDescription = [[UIButton alloc]initWithFrame:CGRectMake(15, 105, 290, 50)];
self.dDescription.titleLabel.font = [UIFont boldSystemFontOfSize:14];
[self.dDescription addTarget:self action:@selector(haveAccount:) forControlEvents:UIControlEventTouchUpInside];
[self.dDescription setTitleColor:customRed forState:UIControlStateNormal];
self.dImage = [[UIImageView alloc]initWithFrame:CGRectMake(15, 160, 290, 250)];
self.dLike = [[UIButton alloc]initWithFrame:CGRectMake(10, 420, 150, 40)];
self.dLike.titleLabel.font = [UIFont boldSystemFontOfSize:14];
[self.dLike addTarget:self action:@selector(haveAccount:) forControlEvents:UIControlEventTouchUpInside];
[self.dLike setTitleColor:customRed forState:UIControlStateNormal];
self.dShare = [[UIButton alloc]initWithFrame:CGRectMake(160, 420, 150, 40)];
self.dShare.titleLabel.font = [UIFont boldSystemFontOfSize:14];
[self.dShare addTarget:self action:@selector(haveAccount:) forControlEvents:UIControlEventTouchUpInside];
[self.dShare setTitleColor:customRed forState:UIControlStateNormal];
[self.contentView addSubview:containerCell];
[self.contentView addSubview:self.dBusinessLogo];
[self.contentView addSubview:self.dBusinessName];
[self.contentView addSubview:self.dTimeAgo];
[self.contentView addSubview:self.dHeading];
[self.contentView addSubview:self.dDescription];
[self.contentView addSubview:self.dImage];
[self.contentView addSubview:self.dShare];
// NSLog(@"Deals View added");
}
return self;
}
這是我的UITableViewCell完全看。
當我向下滾動到下一個單元格,它不正確加載。
它加載後完全正確滾動細胞最多
請幫我解決這個問題。
添加您的cellForRowAtIndexPath代碼以供參考 – NANNAV 2014-10-09 05:53:56
當你的Alloc你的電池,使用initWithReuseIdentifier:或者,它會永遠創建一個新的細胞。 您也可以嘗試使用dequeueReusableCellWithIdentifier:而不是dequeueReusableCellWithIdentifier:forIndexPath: – Imotep 2014-10-09 06:06:31
@Imotep我在viewcontroller中註冊了單元格[dealsTableView registerClass:[pixDealsTableViewCell class] forCellReuseIdentifier:@「Deals」];所以它不會每次都創建新的單元格。我檢查了NSLog。 – Siva777 2014-10-09 06:10:33