viewWillAppear(_:) viewDidDisappear(_:) 查看 SwiftUI

Kis*_*har 8 ios swiftui

我想从上获取数据 viewWillAppear(_:)

是否有任何等于方法或修改现有SwiftUI 也是任何改良剂viewDidDisappear(_:)

Asp*_*eri 3

当然有

@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension View {

    /// Adds an action to perform when this view appears.
    ///
    /// - Parameter action: The action to perform. If `action` is `nil`, the
    ///   call has no effect.
    /// - Returns: A view that triggers `action` when this view appears.
    @inlinable public func onAppear(perform action: (() -> Void)? = nil) -> some View


    /// Adds an action to perform when this view disappears.
    ///
    /// - Parameter action: The action to perform. If `action` is `nil`, the
    ///   call has no effect.
    /// - Returns: A view that triggers `action` when this view disappears.
    @inlinable public func onDisappear(perform action: (() -> Void)? = nil) -> some View

}
Run Code Online (Sandbox Code Playgroud)

  • `onAppear()` 不是与 `viewDidAppear()` 相同而不是 `viewWillAppear()` 吗? (2认同)