0

我正在使用故事板来创建我的应用程序。第一次运行,它将显示所有数据。之后,如果我单击 +,我将添加一个新数据。如果我单击该行,我将移至显示数据的页面。

我正在使用它,但仍然出现错误。这是我的代码。

    -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
    if ([segue.identifier isEqualToString:@"AddUser"])
    {
        UINavigationController *navigationController = segue.destinationViewController;
        UserDetailViewController *userDetailViewController = [[navigationController viewControllers] objectAtIndex:0];
        userDetailViewController.delegate = self;
    }
    else if ([segue.identifier isEqualToString:@"UpdateUser"])
    {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        UserNHG *usernhg = [ListUserNHG objectAtIndex:indexPath.row];

        UINavigationController *navigationController = [segue.destinationViewController setUsernhg:usernhg]; // i got my error here  
        UserDetailViewController *userDetailViewController = [[navigationController viewControllers] objectAtIndex:0];
        userDetailViewController.delegate = self;
    }
}

这是我的错误信息

Initializing 'UINavigationController *__strong' with an expression of incompatible type 'void';

如果我只使用这个,我不会得到错误。

UINavigationController *navigationController = [segue destinationViewController];

但如果我使用该代码,我该如何传递我的对象?知道如何解决这个问题吗?

4

2 回答 2

0

像这样使用:

 AppDelegate *objAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
 UINavigationController *navigationController = (UINavigationController *)objAppDelegate.window.rootViewController;
 UserDetailViewController *userDetailViewController = (UserDetailViewController *)[[navigationController viewControllers] objectAtIndex:0]; //must know correctly index of UserDetailViewController

编辑:如何pass object

Create UserNHG *selectedUser property in UserDetailViewController.

现在

userDetailViewController.selectedUser =  usernhg; //object passed
于 2012-10-31T12:21:15.747 回答
0

我只是通过参考这个链接找到它

这是我的代码:

NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    UserNHG *usernhg = [ListUserNHG objectAtIndex:indexPath.row];

UINavigationController *navigationController = [segue destinationViewController];
    TestViewController *testViewController = [[navigationController viewControllers] objectAtIndex:0];
    testViewController.usernhg = usernhg;
testViewController.delegate = self;

谢谢你的时间。:)

于 2012-10-31T15:09:15.800 回答