遷移した先のnavigationControllerの右側にボタンを追加しようとして以下のコードを試しても全然ボタンが現れなかった。
uploadButton = UIBarButtonItem(title: "Upload", style: UIBarButtonItemStyle.plain, target: self, action: #selector(self.upload(images:)))
navigationController.navigationItem.rightBarButtonItem = uploadButton
しかし、以下のコードで実現できた。
uploadButton = UIBarButtonItem(title: "Upload", style: UIBarButtonItemStyle.plain, target: self, action: #selector(self.upload(images:)))
navigationController.topViewController?.navigationItem.rightBarButtonItem = uploadButton
ドキュメントを見るとしっかり書いてある。
var rightBarButtonItem: UIBarButtonItem?
A custom bar button item displayed on the right (or trailing) edge of the navigation bar **when the receiver is the top navigation item.**
ドキュメントはしっかり読みましょう。
cf. https://developer.apple.com/reference/uikit/uinavigationitem/1624957-rightbarbuttonitem