ios - 如果需要,如何重新创建主 Storyboard

标签 ios xcode swift

我正在创建一个记事卡应用程序,我需要能够根据需要多次制作新的记事卡。我想这样做是为了让用户不受笔记卡数量的限制。如果他们愿意,我需要知道如何创建一个新的 View Controller (或记事卡)。因此,他们创建的页面可以相同,但新的记事卡不能与上一张记事卡的 View 相同,否则它不会是他们创建的新记事卡。言归正传,我正在尝试为已创建的新记事卡创建新 View 。

最佳答案

将 Storyboard 中的场景视为模板。当您从 Storyboard 中调用 View Controller 时,您会得到一个新副本。

假设您的应用有一个主视图 Controller ,上面有一个“创建记事卡”按钮。您可以将该按钮连接到一个 IBAction,该 IBAction 实例化并显示您的记事卡 View Controller 的新副本。 IBAction 方法可能如下所示:

@IBAction func createNoteCard(UIButton sender)
{
  //Create a new instance of a Note card view controller
  let newCard = 
    self.storyboard.instantiateViewControllerWithIdentifier("NoteCard")

  //Put your code to configure the view controller here.

  //Display the new note card view controller to the screen
  self.presentViewController(newCard, animated: true)
}

关于ios - 如果需要,如何重新创建主 Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34302838/

相关文章:

ios - 无法以数字方式对 NSArray 中的自定义对象进行排序

ios - 更改自定义 UIButton 的 TitleColor (iOS 8 + swift)

swift - 从 Swift 中的结构中提取数据

swift - RxSwift asDriver 图和强自

ios - Xcode 6 无法构建 iCloud 项目

ios - SpriteKit touchesBegan 没有按建议工作

iphone - DynamoDB - 新放置的项目未反射(reflect)在扫描中

ios - 在 ShareExtension 中访问网站 URL 和标题

swift - 无法在 UITextfield 上添加操作以查看 Controller

xcode - 在 swift 中使用解析填充图像数组