重定向细节VC无法点击Xcode 7中的UITableView&Cell

时间:2018-01-03 05:30:05

标签: ios objective-c xcode xcode7

我试图按照这个(https://www.appcoda.com/use-storyboards-to-build-navigation-controller-and-table-view/)教程制作一个简单的iOS应用程序但是当我尝试点击列出的项目时,我没有被重定向到详细视图只是呆在同一页上。我使用Xcode(我使用的是Xcode 7)和Objective-C是相当新的,所以我不知道我在做什么。任何形式的帮助都会非常明显。

4 个答案:

答案 0 :(得分:2)

请遵循以下代码:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
       [self performSegueWithIdentifier:@"Your Segue Name" sender:self];

}

pragma mark - 导航

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.

if ([segue.identifier isEqualToString:@"Your Segue Name"]) {
    DetailViewController *vc= (DetailViewController *)segue.destinationViewController;
    NSIndexPath *indexPath = [tableview indexPathForSelectedRow];
    vc.(DetailViewController Object)= [(Your tableView Array name) objectAtIndex:indexPath.row];
    }
}

答案 1 :(得分:2)

在您的情况下,故事板ID为RecipeBookViewController

您必须为该View控制器设置Storyboard ID,如下所述。

GO在Xcode实用程序中,单击Identity Inspector并设置

故事板ID = RecipeBookViewController

有关详细说明,请参阅图片,并针对Storyboard ID添加RecipeBookViewController

enter image description here

答案 2 :(得分:1)

在appCoda中,他们使用segue推送,因此您可能不会在项目中添加此代码,

  - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  {
     if ([segue.identifier isEqualToString:@"segue_Key"]) {
      DetailViewController *nextVC = [segue destinationViewController];

    }
}
  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
    [self performSegueWithIdentifier:@"segue_Key" sender:self];
  }

如果您在segue中遇到问题,请从故事板中删除segue连接并使用以下代码

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
         DetailViewController *obj = (DetailViewController *) [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"]; // Identifier must match with the storyboard VC ID, else project git crashed.

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

    }

如果你已经这样做了,请告诉我。

答案 3 :(得分:1)

如果您不想使用segue,则应按代码创建目标控制器:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    destinationcontroller *loading = (destinationcontroller *)[self.storyboard instantiateViewControllerWithIdentifier:@"destinationcontroller"];
    [self.navigationController pushViewController:loading animated:YES];
}