> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/ios/basic-operations/open/doc-tabbed.md).

# Show documents in a tabbed ViewController with Apryse iOS SDK

Learn how to open a document using a tabbed document view controller. The Apryse iOS SDK streamlines secure document processing and seamlessly integrates with major frameworks like Xamarin, React Nati

The [`PTTabbedDocumentViewController`](https://sdk.apryse.com/api/ios/Classes/PTTabbedDocumentViewController.html) class is a container view controller that hosts multiple [`PTDocumentController`](https://sdk.apryse.com/api/ios/Classes/PTDocumentController.html)[s](https://sdk.apryse.com/api/ios/Classes/PTDocumentController.html) with a tabbed interface. For more information about the `PTDocumentController` class, please see [this guide](/ios/basic-operations/open/doc-view.md).

![](https://4149080208-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgY6xtY9ZQd9XMpvWlGM0%2Fuploads%2Fgit-blob-88e1b1f499ccd3ccf7b025be33e3ed027d4232b4%2F53e038b02f332f9d803397f455b64f6b16065c40-1200x739.png?alt=media)

On iPads or other devices with a Regular [horizontal size class](https://developer.apple.com/uikit/uitraitcollection/) then the tabs will be shown in a bar along the top of the view, for Compact size classes the tabs will be accessible in the UIToolbar at the bottom of the view.

*The tabbed viewer control is part of the Tools library, so make sure you have* [*added the Tools library to your project*](/ios/ui-customization/setup.md)*.*

## Show a tabbed viewer controller

The following sample demonstrates how to show a tabbed viewer controller with a document from another `UIViewController`:

{% tabs %}
{% tab title="Swift" %}
{% code lineNumbers="true" %}

```swift
// Create and wrap a tabbed controller in a navigation controller.
let tabbedController = PTTabbedDocumentViewController()

let navigationController = UINavigationController(rootViewController: tabbedController)

// Open an existing local file URL.
let fileURL: URL! = Bundle.main.url(forResource: "sample", withExtension: "pdf")

tabbedController.openDocument(with: fileURL)

// Show navigation (and tabbed) controller.
self.present(navigationController, animated: true, completion: nil)
```

{% endcode %}
{% endtab %}

{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
// Create and wrap a tabbed controller in a navigation controller.
PTTabbedDocumentViewController *tabbedController = [[PTTabbedDocumentViewController alloc] init];

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:tabbedController];

// Open an existing local file URL.
NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"Sample" withExtension:@"pdf"];

[tabbedController openDocumentWithURL:fileURL];

// Show navigation (and tabbed) controller. 
[self presentViewController:navigationController animated:YES completion:nil];
```

{% endcode %}
{% endtab %}
{% endtabs %}

The `openDocumentWithURL:` method will create a new tab if the URL is not already being displayed, otherwise it will switch to the existing tab.

The tabbed viewer controller currently relies on the `UINavigationController` to supply a navigation bar for the buttons.

## Tab management

For more control over how tabs are added to the tabbed viewer controller, the `addTabWithURL:selected:error:` and `insertTabWithURL:atIndex:selected:error:` methods can be used:

{% tabs %}
{% tab title="Swift" %}
{% code lineNumbers="true" %}

```swift
// Add the fileURL to the end of the tab bar, without changing the selected tab.
do {
	try tabbedController.addTab(with: fileURL selected:false)
} catch {
	// Failed to add tab.
}

// Insert and select the otherFileURL at the start of the tab bar.
do {
	try tabbedController.insertTab(with: otherFileURL, at: 0, selected:true)
} catch {
	// Failed to insert and select tab.
}
```

{% endcode %}
{% endtab %}

{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
// Add the fileURL to the end of the tab bar, without changing the selected tab.
NSError *error = nil;
BOOL success = [tabbedController addTabWithURL:fileURL selected:NO error:&error];
if (!success) {
	// Failed to add tab.
}

// Insert and select the otherFileURL at the start of the tab bar.
error = nil;
success = [tabbedController insertTabWithURL:otherFileURL atIndex:0 selected:YES error:&error];
if (!success) {
	// Failed to insert and select tab.
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Configure the tab bar

The behavior of the tabbed viewer controller can be customized with several properties. The `tabsEnabled` and `maximumTabCount` properties can be used to disable the tab bar and limit the number of tabs, respectively. By default, tabs are enabled in the tabbed viewer controller and there is no limit on the number of tabs.

### Tab bar visibility

The tab bar's visibility is controlled by the `tabBarHidden` property. To animate the change in visibility, the `setTabBarHidden:animated:` method can be used.

When the containing navigation controller's navigation bar is hidden, the tabbed viewer also hides its tab bar.

## Tabbed viewer controller delegate

To configure a document view controller before it is displayed, conform to and implement the [`PTTabbedDocumentViewControllerDelegate`](https://sdk.apryse.com/api/ios/Protocols/PTTabbedDocumentViewControllerDelegate.html#/c:objc\(pl\)PTTabbedDocumentViewControllerDelegate\(im\)tabbedDocumentViewController:willAddDocumentViewController:) method [`tabbedDocumentViewController:willAddDocumentViewController:`](https://sdk.apryse.com/api/ios/Protocols/PTTabbedDocumentViewControllerDelegate.html#/c:objc\(pl\)PTTabbedDocumentViewControllerDelegate\(im\)tabbedDocumentViewController:willAddDocumentViewController:). Note that it **is** permissible to assign the internal `PTDocumentController`'s delegate to an external object.

{% tabs %}
{% tab title="Swift" %}
{% code lineNumbers="true" %}

```swift
func tabbedDocumentViewController(_ tabbedDocumentViewController: PTTabbedDocumentViewController, willAdd documentViewController: PTDocumentController) {

        documentViewController.delegate = self
        // customize documentViewController
    }
```

{% endcode %}
{% endtab %}

{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
-(void)tabbedDocumentViewController:(PTTabbedDocumentViewController *)tabbedDocumentViewController willAddDocumentViewController:(PTDocumentController *)documentViewController
{
    documentViewController.delegate = self;
    // customize documentViewController
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

You can set a delegate to be notified by the tabbed viewer controller when tabs are removed with the `PTTabbedDocumentViewControllerDelegate` protocol's `tabbedDocumentViewController:willRemoveTabAtIndex:` method.

The `tabbedDocumentViewController:willRemoveTabAtIndex:` delegate method can be used to close the tabbed viewer controller when the last tab is closed:

{% tabs %}
{% tab title="Swift" %}
{% code lineNumbers="true" %}

```swift
func tabbedDocumentViewController(_ tabbedDocumentViewController: PTTabbedDocumentViewController, willRemoveTabAt index: UInt) {
  	// Check if the last tab is being removed.
    if (tabbedDocumentViewController.tabURLs.count > 1) {
        return
    }
        
    // Close tabbed viewer controller.
    // ...
}
```

{% endcode %}
{% endtab %}

{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
- (void)tabbedDocumentViewController:(PTTabbedDocumentViewController *)tabbedDocumentViewController willRemoveTabAtIndex:(NSUInteger)index
{
    // Check if the last tab is being removed.
    if (tabbedDocumentViewController.tabURLs.count > 1) {
        return;
    }
    
    // Close tabbed viewer controller.
    // ...
}
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/ios/basic-operations/open/doc-tabbed.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
