【问题标题】:Navigation button back button shows the same viewcontroller导航按钮后退按钮显示相同的视图控制器
【发布时间】:2013-05-05 01:23:50
【问题描述】:

附件是我创建的单视图 iPhone 应用程序的快照。我有一个从事件单元到第二个屏幕,即受邀者列表的转场。我有另一个从 Invitees 到 Checkin 的 segue。因此,当我从“事件”转到“受邀者”时,导航按钮会显示“事件”,这正是我想要的。但是,当我单击 Lisa Webb 单元格时,在签入时,导航按钮会显示 Lisa Webb。当我单击 Lisa Webb 导航按钮时,我会看到相同的签到页面,但现在导航按钮显示事件 A,这是我在事件列表上单击的。我想在签到页面上显示受邀者而不是 Lisa Webb,然后返回受邀者。我不知道该怎么做。我正在使用导航控制器。

下面是我的prepareForSegue代码,从Invitees(2nd)到Checking(3rd)

#pragma mark - Segue
       -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        if ([[segue identifier] isEqualToString:@"InviteesToCheckIn"]) {
            //UIViewController *inviteesViewController = [segue destinationViewController];
            CheckInViewController *checkInViewController = [segue destinationViewController];
            // In order to manipulate the destination view controller, another check on which table     (search or normal) is displayed is needed
            if(sender == self.searchDisplayController.searchResultsTableView) {
                NSIndexPath *indexPath = [self.searchDisplayController.searchResultsTableView      indexPathForSelectedRow];
            NSString *destinationTitle = [[filteredInviteesArray objectAtIndex:[indexPath row]] InviteeName];
            NSNumber *selectedInviteeId = [[filteredInviteesArray objectAtIndex:[indexPath row]] InviteeId];
            [checkInViewController setTitle:destinationTitle];
            checkInViewController.inviteeId = selectedInviteeId;
        }
        else {
            NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
            NSString *destinationTitle = [[theInvitees objectAtIndex:[indexPath row]] InviteeName];
            NSNumber *selectedInviteeId = [[theInvitees objectAtIndex:[indexPath row]] InviteeId];
            [checkInViewController setTitle:destinationTitle];
            checkInViewController.inviteeId = selectedInviteeId;
        }

    }
}

pragma mark - 表视图委托

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     */
    [self performSegueWithIdentifier:@"InviteesToCheckIn" sender:tableView];
}

【问题讨论】:

  • 很难从您的描述中看出发生了什么——您需要更全面地描述您在 IB 中设置的内容。如果您可以发布一张显示您的 segues 的图片,那就太好了。
  • 我已将图像添加到 segues(第 5 张图片)
  • 我仍然对发生的事情感到困惑。你是说当你在 CheckInViewController 中(标题为 Lisa Webb 和返回按钮 Lisa Webb),然后你点击返回按钮,它会带你到另一个 CheckInViewController 场景,标题是 Lisa Webb,后面是 Event A按钮?
  • 是的,这就是现在正在发生的事情。我想要做的是当我从被邀请者(第 2 次)转到检查(第 3 次)时,我希望导航 btn 显示被邀请者,并且标题显示我单击的“LIsa Web”(或任何一个)名称。现在,当我单击受邀者上的名称时,我看到 Lisa Webb 作为导航和标题中的文本。当我点击 Lisa webb back btn 时,我看到另一个 CheckIn 但这次我看到 Event A 作为导航 btn 中的文本
  • 您似乎有 2 个问题。您将标题设置为 InviteeName。只是不要那样做。你应该给每个控制器你想要的标题,比如第二个控制器的 Invitees,然后不要在 CheckInController 中做任何事情来设置标题。但是从您所展示的内容来看,没有意义的是单击 CheckInController 中的后退按钮如何将您带到另一个 CheckInController。您是在代码中执行任何推送、弹出等操作,还是仅使用您显示的 segues 进行导航?

标签: ios navigation


【解决方案1】:

如果您想像您所说的那样将以前的标题更改为字面上的“受邀者”,那么只需在 segue 之前设置 self.title = @"invitees" (prepareForSegue 方法)。然后导航将在下一页上显示后退按钮。当您返回时(使用退出 segue 或 pop,您可以将标题设置回 Event A 或您请求的任何内容。

【讨论】:

  • 你好 Mark,当我从 Invitees 转到 Checkin 时,我正在设置下一个视图控制器的标题。但这也设置了导航按钮的文本(见图 3)。我希望第三张图片上的导航 btn 显示受邀者,并将标题作为我在第二张图片中单击的名称。
  • 后退按钮标题设置为之前的视图控制器标题。因此,如果您想更改该标题,则需要更改前一个视图控制器的标题。如果您希望显示的 viewControllers 文本是其他内容,则需要从前一个控制器中的 prepareForSegue 方法进行设置。您可以通过在 prepareForSegue 方法中传递它或通过访问导航堆栈的 viewControllers(1 个视图返回)来获取对前一个控制器的引用。
猜你喜欢
  • 1970-01-01
  • 2018-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-01
  • 2011-03-26
  • 2014-02-16
  • 1970-01-01
相关资源
最近更新 更多