我是iOS开发的初学者。我在iOS中制作了一个导航应用程序,以便在点击表格视图单元格时在另一个视图中查看一些细节。我做了以下代码,

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath    {
   LawyerViewController *dvc = [self.storyboard    instantiateViewControllerWithIdentifier:@"LawyerViewController"];
   NSLog(@"%@",[self.myObject objectAtIndex:indexPath.row]);
   dvc.lawyer = [self.myObject objectAtIndex:indexPath.row];
   [self.navigationController pushViewController:dvc animated:YES];
}


这将转到下一个视图。但是dvc.lawyer在这里不为空。在“下一个视图”页面上为空。

在下一页中读取值

NSLog(@"%@",self.lawyer.firstName);




我怎样才能解决这个问题。

提前致谢!

最佳答案

如果使用情节提要脚本,则应该以另一种方式实例化ViewController。您需要实现prepareForSegue,您可以在其中访问segues destinationViewController,如下所示:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"YOUR_SEGUE_NAME_HERE"])
    {
        // reference to the destination view controller
        LawyerViewController *vc = [segue destinationViewController];

        // Pass any data
        vc.lawyer = self.myObject[[self.tableView indexPathForSelectedRow].row]; // Not tested
    }
}

关于ios - 无法推送到iOS中的View Controller,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24978516/

10-14 19:37
查看更多