<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSPopUpButtonCell/insertItem(withTitle:at:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSPopUpButtonCell(im)insertItemWithTitle:atIndex:"
  },
  "title" : "insertItem(withTitle:at:)"
}
-->

# insertItem(withTitle:at:)

Inserts an item at the specified position in the menu.

```
func insertItem(withTitle title: String, at index: Int)
```

## Parameters

`title`

The title of the new item. If an item with the same title already exists in the menu, the existing item is removed and the new one is added

`index`

The zero-based index at which to insert the item. Specifying `0` inserts the item at the top of the menu.

## Discussion

The value in `index` must represent a valid position in the array. The menu item at `index` and all those that follow it are shifted down one slot to make room for the new menu item.

This method assigns the pop-up button’s default action and target to the new menu item. Use the menu item’s setAction: and setTarget: methods to assign a new action and target.

Because this method searches for duplicate items, it should not be used if you are adding an item to an already populated menu with more than a few hundred items. In a situation like this, add items directly to the button’s menu instead.

## See Also

  <doc://com.apple.documentation/documentation/Foundation/NSMutableArray/insert(_:at:)-5dbx5>



---

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)