---
title: "insertSegment(action:at:animated:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uisegmentedcontrol/insertsegment(action:at:animated:)"
---

# insertSegment(action:at:animated:)

Insert a segment with the action you specify at the given index.

## Declaration

```swift
func insertSegment(action: UIAction, at segment: Int, animated: Bool)
```

## Parameters

- `action`: A doc://com.apple.uikit/documentation/UIKit/UIAction object to set on the segment at the index you specify.
- `segment`: An unsigned integer index of a segment.
- `animated`: doc://com.apple.documentation/documentation/Swift/true if the insertion of the new segment animates; otherwise, doc://com.apple.documentation/documentation/Swift/false.

## Discussion

Discussion Segments prefer images over titles when the action contains both. Selecting a segment invokes the action’s UIActionHandler, as well as handlers for the valueChanged and primaryActionTriggered control events. If a segment exists with the action’s identifier, this method updates the existing segment is if the index is the same or removes the segment if the index is different.

## See Also

### Managing segments

- [numberOfSegments](uikit/uisegmentedcontrol/numberofsegments.md)
- [segmentIndex(identifiedBy:)](uikit/uisegmentedcontrol/segmentindex(identifiedby:).md)
- [insertSegment(with:at:animated:)](uikit/uisegmentedcontrol/insertsegment(with:at:animated:).md)
- [insertSegment(withTitle:at:animated:)](uikit/uisegmentedcontrol/insertsegment(withtitle:at:animated:).md)
- [removeAllSegments()](uikit/uisegmentedcontrol/removeallsegments().md)
- [removeSegment(at:animated:)](uikit/uisegmentedcontrol/removesegment(at:animated:).md)
- [selectedSegmentIndex](uikit/uisegmentedcontrol/selectedsegmentindex.md)
- [noSegment](uikit/uisegmentedcontrol/nosegment.md)
