2017-09-06 10 views
3

アップルウォッチの問題に直面しています。アップルのコンプリート私の情報が表示されない時計

私は画像といくつかのテキストを合併症に表示しようとしています。私はクロックのインターフェイス上で問題を選択することができますが、それは何もアプリのタイトルと " - "文字でいっぱいの2行を示していません。私は途中でブレークポイントを配置する場合

func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) { 
    // This method will be called once per supported complication, and the results will be cached 
    handler(nil) 
    var template: CLKComplicationTemplateModularLargeColumns? 
    switch complication.family { 
    case .modularSmall: 
     template = nil 
    case .modularLarge: 
     let modularLargeTemplate = 
      CLKComplicationTemplateModularLargeColumns() 
     modularLargeTemplate.row1ImageProvider = 
      CLKImageProvider(onePieceImage: UIImage(named: "GreenUser")!) 
     modularLargeTemplate.row2ImageProvider = 
      CLKImageProvider(onePieceImage: UIImage(named: "GreenUser")!) 
     modularLargeTemplate.row3ImageProvider = 
      CLKImageProvider(onePieceImage: UIImage(named: "GreenUser")!) 

     modularLargeTemplate.row1Column1TextProvider = CLKSimpleTextProvider(text: "User: ") 
     modularLargeTemplate.row1Column2TextProvider = CLKSimpleTextProvider(text: "ok") 

     modularLargeTemplate.row2Column1TextProvider = CLKSimpleTextProvider(text: "Car: ") 
     modularLargeTemplate.row2Column2TextProvider = CLKSimpleTextProvider(text: "ok") 

     modularLargeTemplate.row3Column1TextProvider = CLKSimpleTextProvider(text: "Environment: ") 
     modularLargeTemplate.row3Column2TextProvider = CLKSimpleTextProvider(text: "ok") 

     template = modularLargeTemplate 
    case .utilitarianSmall: 
     template = nil 
    case .utilitarianLarge: 
     template = nil 
    case .circularSmall: 
     template = nil 
    default: 
     template = nil 
    } 
    handler(template) 

} 

合併症はなく、私の情報を表示する必要がありますが、私は自分のコードここ

で間違っているものを見ていないコードでありますデバッガはそれをトリガするので、このコードを実行します。しかし、私が望むようなものは何も表示されません。

何が間違っているか見つからないことがありますか?

+0

最初に 'handler(nil)'を呼び出すのはなぜですか?あなたの関数全体は実行されません。すぐに 'nil'クロージャーを返します。 –

+0

@DávidPásztorその行を削除しようとしましたが、結果は同じです –

+0

関数が呼び出されたかどうか、呼び出されたときに 'template'が' nil'であるかどうかを実際に確認しましたか? –

答えて

0

これはちょうどテンプレートであり、あなたはgetCurrentTimelineEntryの世話をする必要がありますが、最も簡単なのはテンプレートと同じエントリを返すことです(下記参照)。 コメントに記載されている他のものと同様に、コード内でhandler(nil)も削除する必要があります。

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) { 
     getLocalizableSampleTemplate(for: complication) {template in 
      guard let template = template else { 
       handler(nil) 
       return 
      } 
      handler(CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)) 
     } 
    } 
関連する問題