2017-03-15 8 views
0

2つのビュータイプを持つカレンダーココアポッド(CVCalendar:https://github.com/CVCalendar/CVCalendar)を使用しています。 weekViewとmonthView。次の関数は、ポッドに必要と私はクラス拡張以内にそれを持っている:Swift:viewWillTransition内の関数呼び出しの結果が使用されていません

func presentationMode() -> CalendarMode { 

    let isPhone: Bool = UIDevice.current.userInterfaceIdiom == .phone 
    let isLandscape: Bool = UIDevice.current.orientation.isLandscape 

    if isPhone == true && isLandscape == true { 
     return.weekView 
    } else { 
      return .monthView 
    } 
} 

私はそれが表示されている場合、カレンダーは風景の中にIPhone、またはmonthViewに表示されている場合weekViewを提示しようとしています他に何か。私はその後、viewWillTransitionで関数を呼び出しています:私はpresentationMode警告「への呼び出しの結果 『を取得する上記のコードを使用ししかし

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { 
    super.viewWillTransition(to: size, with: coordinator) 

     self.presentationMode() 

    } 

は』未使用で、ビューはIPhone LanscapeにweekViewに変更されません。

+0

初の機能を更新してください。警告は、 'presentationMode()'の戻り値が何にも割り当てられていないため、 'CVCalendar'の' CalendarMode'を設定する必要があるためです。 –

答えて

1

最初の行 `あなたは関数から戻ってきているので、return.weekView`が実行されません後に` presentationMode() `すべてで

func presentationMode() -> CalendarMode { 
    let isPhone: Bool = UIDevice.current.userInterfaceIdiom == .phone 
    let isLandscape: Bool = UIDevice.current.orientation.isLandscape 

    if isPhone == true && isLandscape == true { 
     return.weekView 
    } else { 
     return .monthView 
    } 
} 

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { 
    super.viewWillTransition(to: size, with: coordinator) 
    self.calendarView.calendarMode = self.presentationMode() 
    self.calendarView.commitCalendarViewUpdate() 
} 
+0

お返事ありがとうございます。感謝の気持ちでテストされたときにカレンダーをweekViewに更新しています!ただし、ビュー内のカレンダーの日のボタン/アイコンは同じ場所にとどまっています。私はviewWillTransition関数内でview.layoutIfNeededを追加しようとしましたが、これはそれにも影響しません。助言がありますか? –

+0

ああ問題ありません。あなたは私の最初の問題をとにかく解決しました。ありがとう! –

関連する問題