iphone - 滚动离开屏幕时 UITableViewCell 附件消失
<p><p>我有一个装满对象的 UITableView。在 <em>didSelectRowAtIndexPath</em> 方法中,我有一个 UITableViewCellAccessoryCheckmark 在选中行时出现,在未选中时消失。</p>
<p>这是 <em>didSelectRowAtIndexPath</em> 方法的代码:</p>
<pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
;
UITableViewCell *curCell = ;
if (curCell.accessoryType == UITableViewCellAccessoryCheckmark) {
;
compareCount = (compareCount - 1);
if (tableView == [ searchResultsTableView]) {
NSString *objBeer = ;
];
]];
}
else {
];
];
}
}
else {
;
compareCount = (compareCount + 1);
if (tableView == [ searchResultsTableView]) {
NSString *objBeer = ;
];
]];
}
else {
];
];
}
}
if (compareCount > 0) {
if (compareOn == YES){
}
else {
compareButton.enabled = YES;
UIImage *image = ;
;
}
}
else {
compareButton.enabled = NO;
;
;
}
}
</code></pre>
<p>我也有这个作为我的<em>cellForIndexPath</em>:</p>
<pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CustomCell";
CustomCell *cell = (CustomCell *) ;
if (cell == nil) {
NSArray *topLevelObjects = [ loadNibNamed:@"CustomCell" owner:self options:nil];
for (id currentObject in topLevelObjects){
if (]){
cell =(CustomCell *) currentObject;
break;
}
}
}
// Setting separate tables correctly....
return cell;
}
</code></pre>
<p>My problem is that when the cell that is selected is scrolled out of view the checkmark associated with that value is now gone when back into view.</p>
<p>我应该怎么做才能使复选标记不消失?</p>
<p>谢谢</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>当您滚动浏览数据时,您的单元格会被重新使用(这就是 dequeueReusableCellWithIdentifier 所做的)。在 didSelectRowAtIndexPath 中获得复选标记的单元格将被回收用于不同的行,并且不再与选中的行有任何连接。</p>
<p>您需要在CellForrowatIndExpath中设置/解开附件 View ,因此当签到的行滚动回到 View 中时,它们会得到适当检查。</p></p>
<p style="font-size: 20px;">关于iphone - 滚动离开屏幕时 UITableViewCell 附件消失,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/5827034/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/5827034/
</a>
</p>
页:
[1]