ios – deselectRowAtIndexPath问题

前端之家收集整理的这篇文章主要介绍了ios – deselectRowAtIndexPath问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我刚开始使用tableViews,我在navigationController中嵌入的viewController中的tableview中有5个单元格.当按下一个单元格时,另一个视图被推入.我的问题是我按下的单元格被选中,但选择不会消失.我尝试过这段代码
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];

NewViewController *newViewController = [[NewViewController alloc] init];

newViewController.theTitle = [self.tableView cellForRowAtIndexPath:indexPath].textLabel.text;

[self.navigationController pushViewController: newViewController animated:YES];

}

tableView在viewDidLoad方法中初始化.仍然当我单击一个单元格时,新的viewController被推入但单元格保持选中状态.这可能是什么问题?

解决方法

您已将代码放在didDeselectRowAtIndexPath中 – 将其放在didSelectRowAtIndexPath中.这是一个容易犯的错误,因为在didSelect之前,didDeselect出现在代码完成中.
原文链接:https://www.f2er.com/iOS/333684.html

猜你在找的iOS相关文章