将其视为您从HTML中了解的复选框.
这是我的尝试:
- (voID)tableVIEw:(UItableVIEw *)tableVIEw dIDSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableVIEw cellForRowAtIndexPath:indexPath]; [tableVIEw reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:YES]; //little flashing animation [tableVIEw deselectRowAtIndexPath:indexPath animated:YES]; [UIVIEw animateWithDuration:2.0f animations:^{ } completion:^(BOol finished) { ; }]; //Mark the selected cell UItableVIEwCell *cell = [tableVIEw cellForRowAtIndexPath:indexPath]; ALog(@"%i",cell.imageVIEw.tag); ALog(@"%i",[[[tableVIEw cellForRowAtIndexPath:indexPath] imageVIEw] tag]); UIImageVIEw *iconimgVIEw = (UIImageVIEw *)[[tableVIEw cellForRowAtIndexPath:indexPath] vIEwWithTag:TAG_IMAGEMARKERCELL]; [iconimgVIEw setimage:[UIImage imagenamed:@"circle-answer-marked.png"]]; //..}
UIImageVIEw在这里定义:
- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath { static Nsstring *CellIDentifIEr = @"Cell"; UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:CellIDentifIEr]; if (cell == nil) { //Add this to cell only once,not everytime a cell is displayed! (Everyhing goes in here) cell = [[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleSubTitle reuseIDentifIEr:CellIDentifIEr]; [[cell textLabel] setNumberOflines:0]; // unlimited number of lines [[cell textLabel] setlineBreakMode:NSlineBreakByWorDWrapPing]; [[cell textLabel] setFont:[UIFont FontWithname:@"PTSans-Regular" size:33 / 2]]; [[cell textLabel] setTextcolor:[self colorFromHexString:color_DEFAulT_TEXT_color]]; cell.indentationLevel = cell.indentationLevel + 2; // //Marker image imgCell_Marker = [[UIImageVIEw alloc]initWithFrame:CGRectMake(10,22,20,20)]; imgCell_Marker.image=[UIImage imagenamed:@"circle-answer.png"]; imgCell_Marker.tag = TAG_IMAGEMARKERCELL; ALog(@"%@",imgCell_Marker); [cell.contentVIEw addSubvIEw:imgCell_Marker]; } //.. return cell;}
奇怪的是,UIImageVIEws有一个预定义的标签,但如果我想在dIDSelectRowAtIndexPath中得到它,那么它总是“0”. (标签的默认值)
提前致谢.
解决方法 你在许多方面都有问题.首先,确定应显示什么图像的信息应该是模型的一部分.因此,当选择一行时,在模型中设置一个标记,表示该项已被标记.同时,找到标记的其他项目并取消标记.现在,重新加载已更改的行.在cellForRowAtIndexPath中,更新请求的单元格以根据模型中的标记信息设置标准或替代图像.
其次,对于你使用标签 – 你在imgCell_Marker和imageVIEw之间混淆了.当你这样做时:
ALog(@"%i",[[[tableVIEw cellForRowAtIndexPath:indexPath] imageVIEw] tag]);
您正在查询默认的imageVIEw,因此标记始终为零.您应该使用vIEwWithTag:TAG_IMAGEMARKERCELL来查找所需的实际图像视图.
总结以上是内存溢出为你收集整理的ios – UITableView在单元格选择上更改图像并重置其他图像全部内容,希望文章能够帮你解决ios – UITableView在单元格选择上更改图像并重置其他图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)