在表格视图中,选择行时,在第二次选择索引路径中的行。这是我的代码
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (!self.thirdvc) {
self.thirdvc=[[UIStoryboard storyboardWithName:@"Main" bundle:nil]instantiateViewControllerWithIdentifier:@"thirdview"];
}
[self.navigationController pushViewController:thirdvc animated:YES]; // this is right way .
}
答案 0 :(得分:1)
确保您的tableview仅允许single selection
。在您的故事板中选择tableview
,从attribute inspector
选择single selection
选择selection
。或者您可以通过代码设置它,
yourTableView.allowsMultipleSelection = NO;
答案 1 :(得分:0)
因为在您第一次选择后,它会被标记为已选中,因此第二次按下时,它将被取消选中。所以只需取消选择行:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (!self.thirdvc) {
self.thirdvc=[[UIStoryboard storyboardWithName:@"Main" bundle:nil]instantiateViewControllerWithIdentifier:@"thirdview"];
}
[self.navigationController pushViewController:thirdvc animated:YES];
}
答案 2 :(得分:0)
您已将thirdvc
声明为该类的实例变量,并且在didSelectRowAtIndexpath
方法中,您将检查它是否为nil,然后将其实例化并将其推送到thirdvc
。所以在第二次,thirdvc不是零,所以它不起作用。为了使其工作,请将代码更改为:
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (!self.thirdvc) {
self.thirdvc=[[UIStoryboard storyboardWithName:@"Main" bundle:nil]instantiateViewControllerWithIdentifier:@"thirdview"];
// [self.navigationController pushViewController:thirdvc animated:YES];
}
[self.navigationController pushViewController:thirdvc animated:YES];
}
答案 3 :(得分:0)
用以下代码替换代码:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.thirdvc = nil;
if (!self.thirdvc) {
self.thirdvc=[[UIStoryboard storyboardWithName:@"Main" bundle:nil]instantiateViewControllerWithIdentifier:@"thirdview"];
}
[self.navigationController pushViewController:thirdvc animated:YES]; // this is right way .
}
答案 4 :(得分:0)
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"cell taped");
NSDictionary *temDict1 =[objects objectAtIndex:indexPath.row];