以编程方式在表行Tap上按VC

时间:2015-02-20 20:21:35

标签: ios objective-c iphone uitableview row

我试图在不使用故事板segue推送到新的View Controller的情况下执行onRowTap方法,但是当点击它时,它只显示indexPath的第一项中的信息,无论哪一行被点击。这是我的代码:

- (void)tableView:(UITableView *)theTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
    NSInteger row = [[self tableView].indexPathForSelectedRow row];
    NSDictionary *insta = [self.instaPics objectAtIndex:row];
    UIStoryboard*  sb = [UIStoryboard storyboardWithName:@"Main"
                                                  bundle:nil];
    InstaPicDetailViewController* vc = [sb instantiateViewControllerWithIdentifier:@"InstagramDetail"];
    vc.detailItem = insta;
    [self.navigationController pushViewController:vc animated:YES];
}

1 个答案:

答案 0 :(得分:2)

将deslectRowAtIndexPath消息调用移动到行变量的赋值下面:

NSInteger row = [[self tableView].indexPathForSelectedRow row];
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];