Ios 为什么我的自定义UITableViewCell在调用DeceloseRowatingIndexPath后仍处于选中状态?
我有一个自定义子类Ios 为什么我的自定义UITableViewCell在调用DeceloseRowatingIndexPath后仍处于选中状态?,ios,objective-c,uitableview,uiviewcontroller,Ios,Objective C,Uitableview,Uiviewcontroller,我有一个自定义子类UITableViewCell(下面的实现),在弹出子视图控制器后,该子类不会被取消选择。我没有使用UITableViewController。我使用的是一个视图包含tableView的UIViewController 下面将出现相关视图,试图取消选择所选单元格: - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; NSIndexPath *selection = [s
UITableViewCell
(下面的实现),在弹出子视图控制器后,该子类不会被取消选择。我没有使用UITableViewController
。我使用的是一个视图包含tableView的UIViewController
下面将出现相关视图,试图取消选择所选单元格:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSIndexPath *selection = [self.tableView indexPathForSelectedRow];
if (selection) {
[self.tableView deselectRowAtIndexPath:selection animated:YES];
}
}
我已经确认调用上述代码时,self.tableView
不是nil
自定义UITableViewCell
子类:
@implementation DSCaseCell
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
}
return self;
}
- (void)setStatus:(NSString *)status
{
_status = status;
self.statusLabelView.backgroundColor = [DSStyles colorForCaseStatus:self.status];
self.statusLabel.text = [self.status capitalizedString];
}
- (void)layoutSubviews
{
if ([self.status isEqualToString:DSInteractionClassFacebookComment]) {
self.iconView.image = [UIImage iconForInteractionClass:self.status];
} else {
self.iconView.image = [UIImage iconForInteractionClass:self.messageClass];
}
self.statusLabel.font = [DSStyles preferredFontForTextStyle:DSFontTextStyleCaption2];
self.statusLabelView.layer.cornerRadius = 3;
self.statusLabelView.backgroundColor = [DSStyles colorForCaseStatus:self.status];
self.statusLabel.text = [self.status capitalizedString];
self.statusLabel.textColor = [DSStyles invertedTextColor];
self.statusLabel.highlightedTextColor = [DSStyles invertedTextColor];
self.fromLabel.font = [DSStyles preferredFontForTextStyle:DSFontTextStyleLightCaption1];
self.timeLabel.font = [DSStyles preferredFontForTextStyle:DSFontTextStyleLightCaption1];
self.descriptionLabel.font = [DSStyles preferredFontForTextStyle:DSFontTextStyleLightCaption1];
[super layoutSubviews];
}
@end
这似乎是由
表视图中的以下代码引起的:didSelectRowAtIndexPath:
UITableViewCell *selectedCell = [self tableView:self.tableView cellForRowAtIndexPath:indexPath];
将其更改为此选项可修复此问题:
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
不确定我第一次尝试时喝了什么。是否为InExpathForSelected如何在视图中返回非零?是的,它是非零。我确认if子句的计算结果为true,并且调用了deselerowForIndeXPath:animated。我想知道viewWillExample在视图管道中出现的时间是否太早。你能试试ViewDidDisplay并看看它是否有效吗?只是试了一下--仍然没有成功。我甚至试着把它放到
tableView:DidSelectRowatineXpath:
中,但没有成功:[tableView取消RowatineXpath:indexPath动画:是]代码>