【发布时间】:2013-01-17 11:45:37
【问题描述】:
在从 first view controller 移动到 second view controller 时,我将 indexpaths 保存在一个数组中,并在加载 first view controller 中的表时返回,如果当前 indexpath 在保存的 indexpaths 数组中,我必须创建一个自定义附件按钮。
但是,当滚动 UITableview 以及所需的单元格时,另一个单元格也会获得自定义按钮。当我在滚动时打印NSindexPaths 时,我得到的是随机值而不是正常值。
对于以上内容,我使用以下代码:
- (UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
// NSLog(@"newdata value is =%d",newData);
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
UITableViewCell *cell = [self.positionsTable dequeueReusableCellWithIdentifier:@"playersInPosition"];
if (cell == nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"playersInPosition"]autorelease];
}
UILabel *lblName = (UILabel *)[cell viewWithTag:100];
[lblName setText:[inputData objectAtIndex:[indexPath row]]];
UILabel *pname = (UILabel *)[cell viewWithTag:102];
[pname setText:[appDelegate.playersNFL objectAtIndex:[indexPath row]]];
for (NSIndexPath *object in appDelegate.indexPathList) {
if ([object isEqual:indexPath]) {
NSLog(@"saved index path values are =%@",appDelegate.savedIndexPath);
UIButton *button = [self ChangeAccessoryButtonStyle:appDelegate.indexPathList[0]];
cell.accessoryView = button;
}
}
return cell;
}
【问题讨论】:
-
用
NSString *CellIdentifier =[NSString stringWithFormat:@"%d",indexPath.row];识别你的单元格 -
你在哪里保存 indexPaths ?你能解释更多你想要达到的目标吗?此外,由于单元重用,当
isEqual的if评估为false 时,您应该有一个带有cell.accessoryView = nil的else 分支。 -
嗨@Templar 我已将 indexPaths 保存在 - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{ } 因为,我在第一个视图控制器中有附件详细信息披露按钮...谢谢回复
标签: ios iphone uitableview