<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSPopUpButton/indexOfItem(withTarget:andAction:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSPopUpButton(im)indexOfItemWithTarget:andAction:"
  },
  "title" : "indexOfItem(withTarget:andAction:)"
}
-->

# indexOfItem(withTarget:andAction:)

Returns the index of the menu item with the specified target and action.

```
func indexOfItem(withTarget target: Any?, andAction actionSelector: Selector?) -> Int
```

## Parameters

`target`

The target object associated with the menu item.

`actionSelector`

The action method associated with the menu item.

## Return Value

The index of the menu item, or `-1` if no menu item contains the specified target and action.

## Discussion

If you specify `NULL` for the `actionSelector` parameter, the index of the first menu item with the specified target is returned. This method invokes the method of the same name of its `NSPopUpButtonCell` object.

---

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)