问题是,当我使用单元格的可重用性时,之前的UIImageVIEw的图像保持原样..我如何删除它并在单元格上正确实现我的内容.
以下是我的代码.
- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath{ Nsstring *isimgOftable = [[self.listofEvents objectAtIndex:indexPath.row] objectForKey:@"Eventimage"]; Nsstring *CellIDentifIEr = @"Cell"; //Nsstring *CellIDentifIEr = [Nsstring stringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row]; UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:CellIDentifIEr]; if(cell == nil) { cell = [[UItableVIEwCell alloc]initWithStyle:UItableVIEwCellStyleDefault reuseIDentifIEr:CellIDentifIEr]; cell.selectionStyle = UItableVIEwCellSelectionStyleNone; if([isimgOftable length] > 0) { UIImageVIEw *imgOfEvent = [[UIImageVIEw alloc] init]; imgOfEvent.tag = 101; [cell.contentVIEw addSubvIEw: imgOfEvent]; } UILabel *lbleventTitle = [[UILabel alloc] init]; lbleventTitle.tag = 102; [cell.contentVIEw addSubvIEw:lbleventTitle]; UILabel *lblDescription = [[UILabel alloc] init]; lblDescription.tag = 103; [cell.contentVIEw addSubvIEw:lblDescription]; } if([isimgOftable length] > 0) { Nsstring *newPath = @""; UIImageVIEw *imgEvent = (UIImageVIEw *) [cell.contentVIEw vIEwWithTag:101]; imgEvent.userInteractionEnabled = YES; newPath = [[GeneralClass getdocumentDirectory] stringByAppendingPathComponent:[[self.listofEvents objectAtIndex:indexPath.row] objectForKey:@"Eventimage"]]; imgEvent.frame = CGRectMake(mainX,4,45,45); imgEvent.backgroundcolor = [UIcolor colorWithRed:(187/255.f) green:(226/255.f) blue:(255/255.f) Alpha:1.0f]; imgEvent.layer.cornerRadius = 7; imgEvent.layer.bordercolor = [UIcolor colorWithRed:(224/255.f) green:(224/255.f) blue:(224/255.f) Alpha:1.0f].CGcolor; imgEvent.layer.borderWIDth = 1; imgEvent.clipsToBounds = YES; imgEvent.image = [UIImage imageWithContentsOffile:newPath]; } UILabel *lbleventTitle = (UILabel*) [cell.contentVIEw vIEwWithTag:102]; . . // Code of UILabel *lbleventTitle UILabel *lbleventDescription = (UILabel*) [cell.contentVIEw vIEwWithTag:103]; . . // Code of UILabel *lbleventDescription return cell;}
注意:我必须要使用单元格的可重用性.我不想修复这样的
Nsstring *CellIDentifIEr = [Nsstring stringWithFormat:@"S%1dR%1d",indexPath.row];
而且我也没有使用UItableVIEwCell类,所以可能无法调用/覆盖prepareForReuse
请给我你的建议.
- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath { Nsstring *isimgOftable = [[self.listofEvents objectAtIndex:indexPath.row] objectForKey:@"Eventimage"]; Nsstring *CellIDentifIEr = @"Cell"; //Nsstring *CellIDentifIEr = [Nsstring stringWithFormat:@"S%1dR%1d",indexPath.row]; UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:CellIDentifIEr]; if(cell == nil) { cell = [[UItableVIEwCell alloc]initWithStyle:UItableVIEwCellStyleDefault reuseIDentifIEr:CellIDentifIEr]; cell.selectionStyle = UItableVIEwCellSelectionStyleNone; UIImageVIEw *imgOfEvent = [[UIImageVIEw alloc] init]; imgOfEvent.tag = 101; [cell.contentVIEw addSubvIEw: imgOfEvent]; UILabel *lbleventTitle = [[UILabel alloc] init]; lbleventTitle.tag = 102; [cell.contentVIEw addSubvIEw:lbleventTitle]; UILabel *lblDescription = [[UILabel alloc] init]; lblDescription.tag = 103; [cell.contentVIEw addSubvIEw:lblDescription]; } UIImageVIEw *imgEvent = (UIImageVIEw *) [cell.contentVIEw vIEwWithTag:101]; imgEvent.hIDden=YES; if([isimgOftable length] > 0) { Nsstring *newPath = @""; imgEvent.hIDden=NO; imgEvent.userInteractionEnabled = YES; newPath = [[GeneralClass getdocumentDirectory] stringByAppendingPathComponent:[[self.listofEvents objectAtIndex:indexPath.row] objectForKey:@"Eventimage"]]; imgEvent.frame = CGRectMake(mainX,45); imgEvent.backgroundcolor = [UIcolor colorWithRed:(187/255.f) green:(226/255.f) blue:(255/255.f) Alpha:1.0f]; imgEvent.layer.cornerRadius = 7; imgEvent.layer.bordercolor = [UIcolor colorWithRed:(224/255.f) green:(224/255.f) blue:(224/255.f) Alpha:1.0f].CGcolor; imgEvent.layer.borderWIDth = 1; imgEvent.clipsToBounds = YES; imgEvent.image = [UIImage imageWithContentsOffile:newPath]; } UILabel *lbleventTitle = (UILabel*) [cell.contentVIEw vIEwWithTag:102]; . . // Code of UILabel *lbleventTitle UILabel *lbleventDescription = (UILabel*) [cell.contentVIEw vIEwWithTag:103]; . . // Code of UILabel *lbleventDescription return cell; }总结
以上是内存溢出为你收集整理的ios – 带可重复使用单元的ImageView全部内容,希望文章能够帮你解决ios – 带可重复使用单元的ImageView所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)