<!--
{
  "availability" : [
    "macOS: 10.8.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSPageControllerDelegate/pageController(_:prepare:with:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSPageControllerDelegate(im)pageController:prepareViewController:withObject:"
  },
  "title" : "pageController(_:prepare:with:)"
}
-->

# pageController(_:prepare:with:)

Prepare the view controller and it’s view for drawing.

```
@MainActor optional func pageController(_ pageController: NSPageController, prepare viewController: NSViewController, with object: Any?)
```

## Parameters

`pageController`

The page controller.

`viewController`

The view controller to prepare for drawing. You should setup the data sources and perform layout.

`object`

The object to display.

## Discussion

If this method is not implemented, then `viewController` object’s `representedObject` is set to the object.

> Note:
> This method is called on the main thread and should return immediately. The view will be asked to draw on a background thread and must support background drawing.

This method is only useful if [`pageController(_:identifierFor:)`](/documentation/AppKit/NSPageControllerDelegate/pageController(_:identifierFor:)) and [`pageController(_:prepare:with:)`](/documentation/AppKit/NSPageControllerDelegate/pageController(_:prepare:with:)) are implemented.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)