• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

iOS:以编程方式将 Segue 推送到多个 View Controller

[复制链接]
菜鸟教程小白 发表于 2022-12-12 23:45:05 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我有 一个 原始 View Controller 和 四个 目标 View Controller 。我希望能够 push 使用导航 Controller 将原始 View Controller ALL 转移到目标 View Controller 。我试过了……

- (IBAction)notificationsButtonPushedid)sender {

    NotificationsViewController *notifications = [[NotificationsViewController alloc]init];

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

}

- (IBAction)messagesButtonPushedid)sender {

    MessagesViewController *messages = [[MessagesViewController alloc] init];

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

}

- (IBAction)settingsButtonPushedid)sender {

      if (canMessage) {

          SettingsViewController *settings = [[SettingsViewController alloc]init];

          [self.navigationController pushViewController:settings animated:YES];
      }

      else {

          NSLog(@"Can't Message");
      }

}

- (IBAction)previewButtonPushedid)sender {

    PreviewViewController *preview = [[PreviewViewController alloc]init];

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

}

这只是给了我一个没有 UI 组件的空 View Controller 。

注意:我也厌倦了“initWithNidName:”并传入了每个目标 View Controller 的storyboardID,它给了我错误:

'Could not load NIB in bundle: 'NSBundle </var/mobile/Applications/B7E025E5-D7D2-4FFD-B49C-E10DF5E94C44/LifePoints.app> (loaded)' with name 'preview' 

我也尝试过...( Storyboard segues 设置为“Push”)

    - (IBAction)notificationsButtonPushedid)sender {

    [self performSegueWithIdentifier"notifications" sender:self];

}

- (IBAction)messagesButtonPushedid)sender {

    if (canMessage) {

        [self performSegueWithIdentifier"messages" sender:self];

    }

    else {
        NSLog(@"Can't Message");
    }
}

- (IBAction)settingsButtonPushedid)sender {

    [self performSegueWithIdentifier"settings" sender:self];

}

- (IBAction)previewButtonPushedid)sender {

    [self performSegueWithIdentifier"preview" sender:self];

}

虽然这确实将目标 View Controller 以适当的转场类型推送到屏幕上,但它确实转场到正确的目标 View Controller 。它似乎只延续到最后一个附加的 Storyboardsegue。

有谁知道如何正确应用它并让它以我正在寻找的形式表现?

编辑

请务必注意,我正在检查“messagesButtonPushed”方法是否满足条件。我正在检查是否允许用户发送消息,如果允许,则转到 VC。



Best Answer-推荐答案


您不需要任何代码来实现基本的转场。

在您的 Storyboard中,确保您的原始 View Controller 嵌入在导航 Controller 中(选择原始 View 并选择编辑->嵌入->导航 Controller )。

然后,您可以简单地控制从四个按钮中的每个按钮拖动到相应的目标 View ,选择“push”作为 segue 类型。然后,您可以单击两个 View 之间的 segue 图标,为每个 segue 指定一个标识符。

您可以删除您的 IBAction 方法以及链接到它们的按钮上的任何操作。

我建议你填写 Storyboard Tutorial了解 Storyboard和转场的工作原理。

如果您确实想以编程方式执行 segue,则可以控制从 View 底部的黄色 View Controller 图标拖动到目的地。然后,您可以根据您的第二个代码使用 performSegueWithIdentifier 调用 segue - 在您的情况下,您可能有两个不同的 segue 并根据购买状态触发商店 segue 或另一个

关于iOS:以编程方式将 Segue 推送到多个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24581450/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap