這讓我在一天中更好的時候發狂。當單元格有UIImageView子視圖時,UITableView體驗波濤洶涌滾動
我有一個UITableView與UIImageViews。這些圖像視圖在tableview的cellForRow函數中加載一個本地保存的PNG文件,並且這種方式可以正常工作,除非tableview停止滾動幾分之一秒,否則當圖像中的一個單元格滾動到可見的位置時可以這麼說。我拖過StackOverflow和谷歌的答案,但我已經來了 - 所以任何幫助將不勝感激。
這裏是我的CellForRow功能代碼:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
if([currSection isEqualToString:@"composer"]){
MySlide *s = [slidesArray objectAtIndex:indexPath.row];
cell.textLabel.hidden = YES;
UIImageView *whiteView = [[UIImageView alloc] initWithFrame:CGRectMake((projectsTable.frame.size.width/2)-150, 4, 204.8, 153.6)];
if([s.slideImage isEqualToString:@""] || s.slideImage == nil){
//no custom image in this cell - go with default background image
whiteView.image = [UIImage imageNamed:@"cellback2.png"];
whiteView.backgroundColor = [UIColor whiteColor];
}else{
cell.layer.shouldRasterize = YES;
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
NSData *data = [[NSData alloc] initWithContentsOfFile:s.slideImage];
UIImage *im = [[UIImage alloc] initWithData:data];
whiteView.image = im;
whiteView.image = [self imageWithImage:whiteView.image CovertToSize:CGSizeMake(204.8,153.6)];
whiteView.backgroundColor = [UIColor whiteColor];
}
[cell.contentView addSubview:whiteView];
[whiteView release];
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
這是發生導致它的每一個創建一個新的小區,分配一個ImageView的,格式化和添加時間.. – vishy 2012-02-06 11:45:12
我忘了提到我試圖在if(cell == nil)語句中設置whiteBack,但是在將新圖像路徑添加到幻燈片對象時,我無法更新imageview的圖像。你能否給我一個簡單的例子說明你如何解決這個問題? – PinkFloydRocks 2012-02-06 11:51:29
檢查我的代碼在答案,我已經更新.. – vishy 2012-02-06 11:55:35