0
我有一個自定義的子類UITableViewCell
(下面的實現),當彈出一個子視圖控制器後沒有被取消選擇。我沒有使用UITableViewController
。我正在使用其視圖包含tableView的UIViewController
。爲什麼在調用deselectRowAtIndexPath之後,我的自定義UITableViewCell保持選中狀態?
下面是相關viewWillAppear中試圖取消選定單元格:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSIndexPath *selection = [self.tableView indexPathForSelectedRow];
if (selection) {
[self.tableView deselectRowAtIndexPath:selection animated:YES];
}
}
我已經證實,self.tableView
不爲零時,上面的代碼被調用。
定製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
indexPathForSelectedRow在viewWillAppear中返回非零值嗎? –
是的,它是非零。我確認if子句正在評估爲true,並且deselectRowForIndexPath:animated被調用。 –
我不知道viewWillAppear在視圖管道中是否太早。你可以嘗試viewDidAppear,看看是否有用? –