【问题标题】:Modal Segue in WatchKit not calling contextForSegueWithIdentifierWatchKit 中的模态 Segue 不调用 contextForSegueWithIdentifier
【发布时间】:2015-03-14 23:37:08
【问题描述】:

我有一个带有表格视图的 InterfaceController。我从 tableview 的一个单元格创建了一个 segue 到另一个 InterfaceController。如果 segue 类型是“Push”,则调用 contextForSegueWithIdentifier。如果类型是“模态”,则不会调用 contextForSegueWithIdentifier

【问题讨论】:

    标签: ios watchkit


    【解决方案1】:

    没关系。根据文档 contextForSegueWithIdentifier 仅在 Push Segue 上被调用。我需要使用

    - (void)table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex

    tableview的调用方法

    -(void)presentControllerWithNames:(NSArray *)names contexts:(NSArray *)contexts
    

    【讨论】:

      【解决方案2】:

      使用表格视图时,请使用此 segue 方法将对象传递给您的 segue。

      - (id)contextForSegueWithIdentifier:(NSString *)segueIdentifier inTable:(WKInterfaceTable *)table rowIndex:(NSInteger)rowIndex {
          return yourObject;
      }
      

      【讨论】:

      • +1。不知道为什么这个建议被否决,因为它绝对正确。如果您在情节提要中设置了选择转场,则希望此函数在您的界面控制器上触发,而不是 contextForSegueWithIdentifier 方法。 table:didSelectRowAtIndex: 也不会触发。
      • 如果你使用模态 segue 你更好的用户:覆盖 func contextsForSegueWithIdentifier(segueIdentifier: String, inTable table: WKInterfaceTable, rowIndex: Int) -> [AnyObject]? { 返回 [你的对象] }
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-16
      • 1970-01-01
      • 2017-02-09
      • 1970-01-01
      相关资源
      最近更新 更多