我使用以下代码获取被点击的tablecell的索引。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
tabBar = [self.storyboard instantiateViewControllerWithIdentifier:@"TabBarController"];
[self.navigationController pushViewController:tabBar animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[tableView setAllowsSelection:YES];
NSLog(@"you have selected %d",indexPath.row);
}
此代码的问题是它只打印一次row的索引值。如果我再次点击tableviews,它不会打印索引值。如何知道我点击了哪个索引?
答案 0 :(得分:1)
试试这个
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
NSLog(@"you have selected %d",indexPath.row);
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[tableView setAllowsSelection:YES];
tabBar = [self.storyboard instantiateViewControllerWithIdentifier:@"TabBarController"];
[self.navigationController pushViewController:tabBar animated:YES];
}
答案 1 :(得分:0)
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UITableViewCell * tableCell = [tableView cellForRowAtIndexPath:indexPath];
BOOL isSelected = (tableCell.accessoryType == UITableViewCellAccessoryCheckmark);
if (isSelected)
{
tableCell.accessoryType = UITableViewCellAccessoryNone;
}
else
{
tableCell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
现在检查附件检查标记何时出现它是否会打印索引路径??