> 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/xamarin/basic-operations/basics/viewer/tabbed-viewer-legacy.md).

# Show Documents in a Tabbed ViewController in Xamarin

Learn how to optimize your viewer with the Legacy Viewer guide. Upgrade to PTDocumentController for the best experience. Explore tabbed viewer control and more. The Apryse Xamarin SDK streamlines secu

{% hint style="info" %}
**Legacy Viewer**

This guide is only valid when using the legacy `PTDocumentViewController` class in a tabbed viewer. This class is no longer being updated. For the best viewing experience and to take advantage of new developments, the `PTDocumentController` should be used. Please see [this guide](/ios/basic-operations/open/doc-tabbed.md) for information.
{% endhint %}

The [`PTTabbedDocumentViewController`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTTabbedDocumentViewController.html) class is a container view controller that hosts multiple [`PTDocumentViewController`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTDocumentViewController.html)[s](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTDocumentViewController.html) with a tabbed interface. For more information about the `PTDocumentViewController` class, please see [this guide](/xamarin/guides/ios/basics/open.md).

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

*The tabbed viewer control is part of the Tools library, so make sure you have* [*added the Tools library to your project*](/xamarin/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="C#" %}
{% code lineNumbers="true" %}

```csharp
PTTabbedDocumentViewController tabbedController = new PTTabbedDocumentViewController();
UINavigationController navigationController = new UINavigationController(tabbedController);
NSUrl fileURL = NSBundle.MainBundle.GetUrlForResource("sample", "pdf");

tabbedController.OpenDocumentWithURL(fileURL);

this.PresentViewController(navigationController, true, null);
```

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

The [`openDocumentWithURL:`](https://sdk.apryse.com/api/ios/Classes/PTDocumentViewController.html#/c:objc\(cs\)PTDocumentViewController\(im\)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:`](https://sdk.apryse.com/api/ios/Classes/PTTabbedDocumentViewController.html#/c:objc\(cs\)PTTabbedDocumentViewController\(im\)addTabWithURL:selected:error:) and [`insertTabWithURL:atIndex:selected:error:`](https://sdk.apryse.com/api/ios/Classes/PTTabbedDocumentViewController.html#/c:objc\(cs\)PTTabbedDocumentViewController\(im\)insertTabWithURL:atIndex:selected:error:) methods can be used:

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
// Add the fileURL to the end of the tab bar, without changing the selected tab.
NSError error = null;
bool success = tabbedController.AddTabWithURL(fileURL, false, out error);
if (!success)
{
    Console.WriteLine("add tab failed...");
}
// Insert and select the otherFileURL at the start of the tab bar.
NSError error = null;
bool success = tabbedController.InsertTabWithURL(otherFileURL, 0, true, out error);
if (!success)
{
    Console.WriteLine("insert and select tab failed...");
}
```

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

## Configure the tab bar

The behavior of the tabbed viewer controller can be customized with several properties. The [`tabsEnabled`](https://sdk.apryse.com/api/ios/Classes/PTDocumentViewController.html#/c:objc\(cs\)PTDocumentViewController\(im\)openDocumentWithURL:) and [`maximumTabCount`](https://sdk.apryse.com/api/ios/Classes/PTTabbedDocumentViewController.html#/c:objc\(cs\)PTTabbedDocumentViewController\(py\)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`](https://sdk.apryse.com/api/ios/Classes/PTTabbedDocumentViewController.html#/c:objc\(cs\)PTTabbedDocumentViewController\(im\)addTabWithURL:selected:error:) property. To animate the change in visibility, the [`setTabBarHidden:animated:`](https://sdk.apryse.com/api/ios/Classes/PTTabbedDocumentViewController.html#/c:objc\(cs\)PTTabbedDocumentViewController\(im\)insertTabWithURL:atIndex:selected:error:) 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/xamarinios/tools/api/pdftron.PDF.Controls.PTTabbedDocumentViewControllerDelegate.html) method [`willAddDocumentViewController`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTTabbedDocumentViewControllerDelegate.html). Note that it **is** permissible to assign the internal `PTDocumentViewController`'s delegate to an external object.

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
tabbedDocumentViewController.WillAddDocumentViewController += (sender, e) =>
{
    // do something with e.DocumentViewController
};
```

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

You can set a delegate to be notified by the tabbed viewer controller when tabs are removed with the [`PTTabbedDocumentViewControllerDelegate`](https://sdk.apryse.com/api/ios/Protocols/PTTabbedDocumentViewControllerDelegate.html) protocol's [`tabbedDocumentViewController:willRemoveTabAtIndex:`](https://sdk.apryse.com/api/ios/Protocols/PTTabbedDocumentViewControllerDelegate.html#/c:objc\(pl\)PTTabbedDocumentViewControllerDelegate\(im\)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="C#" %}
{% code lineNumbers="true" %}

```csharp
tabbedDocumentViewController.WillRemoveTabAtIndex += (sender, e) => {
    if (((PTTabbedDocumentViewController)sender).TabURLs.Length > 1)
    {
        return;
    }
    ((PTTabbedDocumentViewController)sender).DismissViewController(true, null);
};
```

{% 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.apryse.com/xamarin/basic-operations/basics/viewer/tabbed-viewer-legacy.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
